API Reference · Scene and camera

NodeCollection

Namespace: Ava3D

public sealed class NodeCollection

The children of a Node. Mutating it invalidates the scene.

Properties

MemberDescription
int Count { get; }

Number of children.

Node Item { get; }

The child at index.

Methods

MemberDescription
void Add(Node node)

Adds a child, taking it off whatever parent it had.

The detaching is the part worth stating, because leaving it out looks like it works. A node's Node.Parent is one field and can only name one parent, but the old parent's list is a list and would go on holding it — so the node would be walked twice by the renderer, drawn twice, and positioned by the wrong transform in one of the two places. Moving a node from one parent to another is an ordinary thing to want, and it has to be this call rather than a remove-then-add the caller has to remember.

Adding a node to the parent it already has moves it to the end of that parent's children, which is what re-adding means and is the only way to reorder siblings. Within one Node.RenderOrder that is also the order they draw in.

void AddRange(IEnumerable<Node> nodes)

Adds several children in one go.

void Clear()

Removes every child.

bool Contains(Node node)

Whether node is a direct child. See Node.Descendants for the deep question.

List<Node> GetEnumerator()

A struct enumerator, so walking the graph allocates nothing.

int IndexOf(Node node)

Where node sits among the children, or −1 when it is not one.

void Insert(int index, Node node)

Adds a child at index, shifting the rest along. Otherwise exactly NodeCollection.Add — see there for what happens to a node that already has a parent, and for the loop that is refused.

bool Remove(Node node)

Removes a child. Returns false when it was not one.

void RemoveAt(int index)

Removes the child at index, detaching it.

See also