Trait bevy::ecs::system::Command

pub trait Command: Send + 'static {
    // Required method
    fn apply(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 apply(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 apply(self, world: &mut World)

Applies this command, causing it to mutate the provided world.

This method is used to define what a command “does” when it is ultimately applied. Because this method takes self, you can store data or settings on the type that implements this trait. This data is set by the system or other source of the command, and then ultimately read in this method.

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 LogComponents

§

impl Command for RunSystem

§

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,

§

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