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.

See EntityMut::insert for more details.

Warning

It’s possible to call this with a bundle, but this is likely not intended and Self::insert_bundle should be used instead. If with is called with a bundle, the bundle itself will be added as a component instead of the bundles’ inner components each being added.

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();
}

Returns the underlying Commands.

Trait Implementations

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

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

Performs the conversion.

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

Performs the conversion.

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