logo
pub struct EntityCommands<'w, 's, 'a> { /* private fields */ }
Expand description

A list of commands that will be run to modify an entity.

Implementations

Returns the Entity id of the entity.

Example
fn my_system(mut commands: Commands) {
    let entity_id = commands.spawn().id();
}

Adds a Bundle of components to the entity.

Example
fn add_combat_stats_system(mut commands: Commands, player: Res<PlayerEntity>) {
    commands.entity(player.entity).insert_bundle(CombatBundle {
        health: Health(100),
        strength: Strength(40),
        defense: Defense(20),
    });
}

Adds a single Component to the entity.

Example

Self::insert can be chained with Commands::spawn.

fn example_system(mut commands: Commands) {
    // Create a new entity with `Component1` and `Component2`
    commands.spawn()
        .insert(Component1)
        .insert(Component2);

    // The following statements are equivalent to above one.
    commands.spawn().insert_bundle((Component1, Component2));
    commands.spawn_bundle((Component1, Component2));
}

Removes a Bundle of components from the entity.

See EntityMut::remove_bundle for more details.

Example
struct Dummy;
fn remove_combat_stats_system(mut commands: Commands, player: Res<PlayerEntity>) {
    commands.entity(player.entity).remove_bundle::<CombatBundle>();
}

Removes a single component from the entity.

See EntityMut::remove for more details.

Example
fn convert_enemy_system(mut commands: Commands, enemy: Res<TargetEnemy>) {
    commands.entity(enemy.entity).remove::<Enemy>();
}

Despawns the entity.

See World::despawn for more details.

Example
fn remove_character_system(
    mut commands: Commands,
    character_to_remove: Res<CharacterToRemove>
)
{
    commands.entity(character_to_remove.entity).despawn();
}

Logs the components of the entity at the info level.

Returns the underlying Commands.

Trait Implementations

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

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

Pushes children to the back of the builder’s children

Inserts children at the given index

Removes the given children

Adds a single child

Despawns the provided entity and its children.

Despawns all descendants of the given entity.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait. Read more

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait. Read more

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s. Read more

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s. Read more

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more