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.

Object Safety§

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