Skip to main content

Commands

Struct Commands 

Source
pub struct Commands<'w> { /* private fields */ }
Expand description

System parameter that queues structural mutations for deferred application.

Commands buffers spawn, despawn, insert, and remove operations. These are applied between schedule stages via World::apply_commands, avoiding mid-iteration archetype changes.

ⓘ
fn spawn_units(mut cmds: Commands<'_>) {
    cmds.spawn((Position { x: 0.0, y: 0.0 },));
    cmds.despawn(old_entity);
    cmds.insert(entity, Health(100));
    cmds.remove::<Velocity>(entity);
}

Implementations§

Source§

impl<'w> Commands<'w>

Source

pub fn spawn<B: Bundle + Send + 'static>(&mut self, bundle: B)

Spawn an entity with the given component bundle (deferred).

Source

pub fn despawn(&mut self, entity: Entity)

Despawn an entity (deferred).

Source

pub fn insert<C: Component>(&mut self, entity: Entity, component: C)

Insert a component into an entity (deferred).

If the entity already has this component type, the value is overwritten.

Source

pub fn remove<C: Component>(&mut self, entity: Entity)

Remove a component from an entity (deferred).

Source

pub fn schedule_deadline<T: Send + 'static>( &mut self, deadline: Timestamp, event: T, )

Schedule a deadline event (deferred).

The event type must have been registered with World::add_deadline_type::<T>().

Source

pub fn cancel_deadline<T: Send + 'static>(&mut self, id: DeadlineId)

Cancel a previously scheduled deadline (deferred).

Source

pub fn len(&self) -> usize

Returns the number of queued commands.

Source

pub fn is_empty(&self) -> bool

Returns true if no commands are queued.

Trait Implementations§

Source§

impl SystemParam for Commands<'_>

Source§

type Item<'w> = Commands<'w>

The concrete type produced for a given world lifetime.
Source§

fn access() -> Vec<Access>

Declare what world data this parameter accesses.
Source§

unsafe fn fetch<'w>(world: UnsafeWorldCell) -> Commands<'w>

Extract the parameter from the world. Read more

Auto Trait Implementations§

§

impl<'w> !RefUnwindSafe for Commands<'w>

§

impl<'w> !Sync for Commands<'w>

§

impl<'w> !UnwindSafe for Commands<'w>

§

impl<'w> Freeze for Commands<'w>

§

impl<'w> Send for Commands<'w>

§

impl<'w> Unpin for Commands<'w>

§

impl<'w> UnsafeUnpin for Commands<'w>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.