bevy::ecs::prelude

Trait Command

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

A World mutation.

Should be used with Commands::queue.

§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.queue(AddToCounter(42));
}

Required Methods§

source

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§

source§

impl Command for AddChild

source§

impl Command for AddChildren

source§

impl Command for ClearChildren

source§

impl Command for DespawnChildrenRecursive

source§

impl Command for DespawnRecursive

source§

impl Command for InsertChildren

source§

impl Command for RemoveChildren

source§

impl Command for RemoveParent

source§

impl Command for ReplaceChildren

source§

impl Command for AddChildInPlace

source§

impl Command for RemoveParentInPlace

source§

impl<E> Command for SendEvent<E>
where E: Event,

source§

impl<E, Targets> Command for EmitDynamicTrigger<E, Targets>
where E: Event, Targets: TriggerTargets + Send + Sync + 'static,

source§

impl<E, Targets> Command for TriggerEvent<E, Targets>
where E: Event, Targets: TriggerTargets + Send + Sync + 'static,

source§

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

source§

impl<I> Command for RunSystemWithInput<I>
where I: SystemInput + 'static, <I as SystemInput>::Inner<'static>: Send,

source§

impl<I, O> Command for RegisterSystem<I, O>
where I: SystemInput + Send + 'static, O: Send + 'static,

source§

impl<I, O> Command for UnregisterSystem<I, O>
where I: SystemInput + 'static, O: 'static,

source§

impl<S, I, O, M> Command for RunSystemCachedWith<S, I, O, M>
where I: SystemInput + Send + 'static, <I as SystemInput>::Inner<'static>: Send, O: Send + 'static, S: IntoSystem<I, O, M> + Send + 'static, M: 'static,