pub struct Commands<'a> { /* private fields */ }Expand description
Deferred entity spawns and resource/observer mutations — applied at the
end of the current stage, not immediately. Derefs to hecs::CommandBuffer
for spawning/despawning entities and adding/removing components.
Implementations§
Source§impl<'a> Commands<'a>
impl<'a> Commands<'a>
Sourcepub fn insert_resource<T: 'static>(&mut self, value: T)
pub fn insert_resource<T: 'static>(&mut self, value: T)
Queues a resource insert, applied once commands are synced.
Sourcepub fn remove_resource<T: 'static>(&mut self)
pub fn remove_resource<T: 'static>(&mut self)
Queues a resource removal, applied once commands are synced.
Sourcepub fn trigger<E: 'static + Send + Sync>(&mut self, event: E)
pub fn trigger<E: 'static + Send + Sync>(&mut self, event: E)
Queues event to be dispatched to every observer registered for
E via App::add_observer, once
commands are synced (right after the system that called this
returns — same tick, not necessarily end of stage).
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 queue(&mut self, f: impl FnOnce(&mut World) + Send + Sync + 'static)
pub fn queue(&mut self, f: impl FnOnce(&mut World) + Send + Sync + 'static)
Queue an arbitrary operation to be run on a World
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<'a> Deref for Commands<'a>
impl<'a> Deref for Commands<'a>
Source§type Target = CommandBuffer
type Target = CommandBuffer
Source§fn deref(&self) -> &CommandBuffer
fn deref(&self) -> &CommandBuffer
Source§impl<'a> DerefMut for Commands<'a>
impl<'a> DerefMut for Commands<'a>
Source§fn deref_mut(&mut self) -> &mut CommandBuffer
fn deref_mut(&mut self) -> &mut CommandBuffer
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for Commands<'a>
impl<'a> !Send for Commands<'a>
impl<'a> !Sync for Commands<'a>
impl<'a> !UnwindSafe for Commands<'a>
impl<'a> Freeze for Commands<'a>
impl<'a> Unpin for Commands<'a>
impl<'a> UnsafeUnpin for Commands<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more