pub trait BuildChildren {
    fn with_children(
        &mut self,
        f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
    ) -> &mut Self; fn add_children<T>(
        &mut self,
        f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
    ) -> T; fn push_children(&mut self, children: &[Entity]) -> &mut Self; fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self; fn remove_children(&mut self, children: &[Entity]) -> &mut Self; fn add_child(&mut self, child: Entity) -> &mut Self; fn set_parent(&mut self, parent: Entity) -> &mut Self; fn remove_parent(&mut self) -> &mut Self; }
Expand description

Trait defining how to build children

Required Methods§

Creates a ChildBuilder with the given children built in the given closure

Compared to add_children, this method returns self to allow chaining.

Creates a ChildBuilder with the given children built in the given closure

Compared to with_children, this method returns the the value returned from the closure, but doesn’t allow chaining.

Example
    let mut parent_commands = commands.spawn_empty();
    let child_id = parent_commands.add_children(|parent| {
        parent.spawn_empty().id()
    });

    parent_commands.insert(SomethingElse);
    commands.entity(child_id).with_children(|parent| {
        parent.spawn_bundle(MoreStuff);
    });

Pushes children to the back of the builder’s children

If the children were previously children of another parent, that parent’s Children component will have those children removed from its list. Removing all children from a parent causes its Children component to be removed from the entity.

Inserts children at the given index

If the children were previously children of another parent, that parent’s Children component will have those children removed from its list. Removing all children from a parent causes its Children component to be removed from the entity.

Removes the given children

Removing all children from a parent causes its Children component to be removed from the entity.

Adds a single child

If the children were previously children of another parent, that parent’s Children component will have those children removed from its list. Removing all children from a parent causes its Children component to be removed from the entity.

Sets the parent of this entity.

Removes the parent of this entity.

Implementors§