pub struct Commands<'a> { /* private fields */ }Expand description
Deferred world-mutation commands available as a system parameter.
Mutations are buffered and applied to the world after all systems in the current stage have finished running.
Resource insertions immediately bump the Resources generation counter so
that the convergence loop in App can detect them without
needing to inspect the world after every flush.
Implementations§
Source§impl<'a> Commands<'a>
impl<'a> Commands<'a>
Sourcepub fn insert_resource<T: Component>(&mut self, res: T)
pub fn insert_resource<T: Component>(&mut self, res: T)
Queue a resource insertion. Applied after the current stage finishes.
Bumps the Resources generation counter immediately so the
convergence loop knows another pass is needed even before the command
buffer is flushed.
Sourcepub fn remove_resource<T: Component>(&mut self)
pub fn remove_resource<T: Component>(&mut self)
Queue a resource removal. Applied after the current stage finishes.
Methods from Deref<Target = CommandBuffer>§
Sourcepub fn insert(&mut self, entity: Entity, components: impl DynamicBundle)
pub fn insert(&mut self, entity: Entity, components: impl DynamicBundle)
Add components from bundle to entity, if it exists
Pairs well with World::reserve_entity to spawn entities with a known handle.
When inserting a single component, see insert_one for convenience.
Sourcepub fn insert_one(&mut self, entity: Entity, component: impl Component)
pub fn insert_one(&mut self, entity: Entity, component: impl Component)
Add component to entity, if the entity exists
See insert.
Sourcepub fn remove<T>(&mut self, ent: Entity)where
T: Bundle + 'static,
pub fn remove<T>(&mut self, ent: Entity)where
T: Bundle + 'static,
Remove components from entity if they exist
When removing a single component, see remove_one for convenience.
Sourcepub fn remove_one<T>(&mut self, ent: Entity)where
T: Component,
pub fn remove_one<T>(&mut self, ent: Entity)where
T: Component,
Remove a component from entity if it exists
See remove.
Sourcepub fn spawn(&mut self, components: impl DynamicBundle)
pub fn spawn(&mut self, components: impl DynamicBundle)
Spawn a new entity with components
If the Entity is needed immediately, consider combining World::reserve_entity with
insert instead.
Trait Implementations§
Source§impl SystemParam for Commands<'static>
impl SystemParam for Commands<'static>
type Item<'a> = Commands<'a>
type State = ()
fn fetch<'a>( _state: &'a mut Self::State, _world: &'a World, resources: &'a Resources, ) -> Self::Item<'a>
Source§fn requires() -> Vec<RequiredResource>
fn requires() -> Vec<RequiredResource>
App to validate — before
running a non-convergent stage’s systems — that every hard
requirement is already satisfied, failing fast with a clear message
instead of panicking deep inside whichever system happens to run
first. Read more