Trait bevy_internal::hierarchy::BuildChildren
source · 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§
sourcefn with_children(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
) -> &mut Self
fn with_children(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>)
) -> &mut Self
Creates a ChildBuilder
with the given children built in the given closure
Compared to add_children
, this method returns self
to allow chaining.
sourcefn add_children<T>(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
) -> T
fn add_children<T>(
&mut self,
f: impl FnOnce(&mut ChildBuilder<'_, '_, '_>) -> T
) -> T
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);
});
sourcefn push_children(&mut self, children: &[Entity]) -> &mut Self
fn push_children(&mut self, children: &[Entity]) -> &mut Self
sourcefn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self
fn insert_children(&mut self, index: usize, children: &[Entity]) -> &mut Self
sourcefn remove_children(&mut self, children: &[Entity]) -> &mut Self
fn remove_children(&mut self, children: &[Entity]) -> &mut Self
Removes the given children
Removing all children from a parent causes its Children
component to be removed from the entity.
sourcefn set_parent(&mut self, parent: Entity) -> &mut Self
fn set_parent(&mut self, parent: Entity) -> &mut Self
Sets the parent of this entity.
sourcefn remove_parent(&mut self) -> &mut Self
fn remove_parent(&mut self) -> &mut Self
Removes the parent of this entity.