Skip to content

Parent/Child

Parent is a relation like any other, not a special case wired into the engine. It just happens to be the one Wyrd ships for you:

public readonly struct Parent : IRelation, IExclusiveRelation, IDependent { }

Exclusive because a child has one parent at a time. Dependent because destroying a parent should take its subtree with it.

child.SetParent(parent);
child.ClearParent();

SetParent/ClearParent are EntityView mutators, chainable like any other. To reparent, call SetParent alone, a preceding ClearParent costs an extra archetype move for nothing.

From the parent’s side, the same edge, called from whichever entity you have in hand:

parent.AddChild(child);
parent.RemoveChild(child);
world.Children(parent); // direct children
world.Ancestors(entity); // parent chain, closest first
world.Descendants(entity); // every descendant, depth-first
world.TryGetParent(child, out var parent);

Destroying a parent destroys its whole subtree, not just the parent. This comes from Parent implementing IDependent, the same mechanism Relations covers for any relation, not a hierarchy-specific special case.

Relations link existing entities together. For starting several entities from one reusable definition, see Templates.