Trait bevy::ecs::system::Command

pub trait Command: 'static + Send {
    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§

Implementors§