Trait bevy::ecs::system::Command

pub trait Command: Send + 'static {
    // Required method
    fn write(self, world: &mut World);
}
Expand description

A World mutation.

Should be used with Commands::add.

Usage

// Our world resource
#[derive(Resource, Default)]
struct Counter(u64);

// Our custom command
struct AddToCounter(u64);

impl Command for AddToCounter {
    fn write(self, world: &mut World) {
        let mut counter = world.get_resource_or_insert_with(Counter::default);
        counter.0 += self.0;
    }
}

fn some_system(mut commands: Commands) {
    commands.add(AddToCounter(42));
}

Required Methods§

fn write(self, world: &mut World)

Implementors§

§

impl Command for AddChild

§

impl Command for ClearChildren

§

impl Command for DespawnChildrenRecursive

§

impl Command for DespawnRecursive

§

impl Command for InsertChildren

§

impl Command for PushChildren

§

impl Command for RemoveChildren

§

impl Command for RemoveParent

§

impl Command for ReplaceChildren

§

impl Command for AddChildInPlace

§

impl Command for RemoveParentInPlace

§

impl Command for Despawn

§

impl Command for GetOrSpawn

§

impl Command for LogComponents

§

impl<C> Command for WithEntity<C>where C: EntityCommand,

§

impl<F> Command for Fwhere F: FnOnce(&mut World) + Send + 'static,

§

impl<I> Command for SpawnBatch<I>where I: IntoIterator + Send + Sync + 'static, <I as IntoIterator>::Item: Bundle,

§

impl<I, B> Command for InsertOrSpawnBatch<I, B>where I: IntoIterator + Send + Sync + 'static, B: Bundle, <I as IntoIterator>::IntoIter: Iterator<Item = (Entity, B)>,

§

impl<R> Command for InitResource<R>where R: Resource + FromWorld,

§

impl<R> Command for InsertResource<R>where R: Resource,

§

impl<R> Command for RemoveResource<R>where R: Resource,

§

impl<T> Command for Insert<T>where T: Bundle + 'static,

§

impl<T> Command for Remove<T>where T: Bundle,

§

impl<T> Command for Spawn<T>where T: Bundle,