bevy_hierarchy

Trait ChildBuild

Source
pub trait ChildBuild {
    type SpawnOutput<'a>: BuildChildren
       where Self: 'a;

    // Required methods
    fn spawn(&mut self, bundle: impl Bundle) -> Self::SpawnOutput<'_>;
    fn spawn_empty(&mut self) -> Self::SpawnOutput<'_>;
    fn parent_entity(&self) -> Entity;
    fn enqueue_command<C: Command>(&mut self, command: C) -> &mut Self;
}
Expand description

Trait for building children entities and adding them to a parent entity. This is used in implementations of BuildChildren as a bound on the Builder associated type. The closure passed to BuildChildren::with_children accepts an implementation of ChildBuild so that children can be spawned via ChildBuild::spawn.

Required Associated Types§

Source

type SpawnOutput<'a>: BuildChildren where Self: 'a

Spawn output type. Both spawn and spawn_empty return an implementation of this type so that children can be operated on via method-chaining. Implementations of ChildBuild reborrow self when spawning entities (see Commands::spawn_empty and World::get_entity_mut). Lifetime 'a corresponds to this reborrowed self, and Self outlives it.

Required Methods§

Source

fn spawn(&mut self, bundle: impl Bundle) -> Self::SpawnOutput<'_>

Spawns an entity with the given bundle and inserts it into the parent entity’s Children. Also adds Parent component to the created entity.

Source

fn spawn_empty(&mut self) -> Self::SpawnOutput<'_>

Spawns an Entity with no components and inserts it into the parent entity’s Children. Also adds Parent component to the created entity.

Source

fn parent_entity(&self) -> Entity

Returns the parent entity.

Source

fn enqueue_command<C: Command>(&mut self, command: C) -> &mut Self

Adds a command to be executed, like Commands::queue.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl ChildBuild for ChildBuilder<'_>

Source§

type SpawnOutput<'a> = EntityCommands<'a> where Self: 'a

Source§

impl ChildBuild for WorldChildBuilder<'_>

Source§

type SpawnOutput<'a> = EntityWorldMut<'a> where Self: 'a