addChild method

void addChild(
  1. Entity child
)

Appends child to the end of this entity's child list - a doubly-linked splice through firstChild/lastChild and child's own nextSibling/prevSibling.

child must be unparented. It used to splice unconditionally, which meant attaching an already-attached entity left it in two chains: its old parent still named it, its old siblings still pointed at it, and the corruption was silent. There is no legitimate caller for that now that adopt exists, so it is an error.

child must mix in Child - checked at runtime (tryGet<Child>()) since the type system has no way to require "some component that mixes in Child" as a constraint on a bare Entity.

Implementation

void addChild(Entity child) {
  final childComponent = _requireChild(child);
  assert(_sameScene(child));
  assert(_unparented(childComponent, child));
  _append(childComponent, child);
}