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>
impl<'w> Commands<'w>
Sourcepub fn spawn<B: Bundle + Send + 'static>(&mut self, bundle: B)
pub fn spawn<B: Bundle + Send + 'static>(&mut self, bundle: B)
Spawn an entity with the given component bundle (deferred).
Sourcepub fn insert<C: Component>(&mut self, entity: Entity, component: C)
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.
Sourcepub fn remove<C: Component>(&mut self, entity: Entity)
pub fn remove<C: Component>(&mut self, entity: Entity)
Remove a component from an entity (deferred).
Sourcepub fn schedule_deadline<T: Send + 'static>(
&mut self,
deadline: Timestamp,
event: T,
)
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>().
Sourcepub fn cancel_deadline<T: Send + 'static>(&mut self, id: DeadlineId)
pub fn cancel_deadline<T: Send + 'static>(&mut self, id: DeadlineId)
Cancel a previously scheduled deadline (deferred).
Trait Implementations§
Source§impl SystemParam for Commands<'_>
impl SystemParam for Commands<'_>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more