pub struct CommandBuffer { /* private fields */ }Expand description
Records operations for future application to a Substrate
Useful when operations cannot be applied directly due to ordering concerns or borrow checking.
let mut world = Substrate::new();
let entity = world.reserve_entity();
let mut cmd = CommandBuffer::new();
cmd.insert(entity, (true, 42));
cmd.run_on(&mut world); // cmd can now be reused
assert_eq!(*world.get::<&i32>(entity).unwrap(), 42);Implementations§
Source§impl CommandBuffer
impl 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 Substrate::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: Bundle + 'static>(&mut self, ent: Entity)
pub fn remove<T: Bundle + 'static>(&mut self, ent: Entity)
Remove components from entity if they exist
When removing a single component, see remove_one for convenience.
Sourcepub fn remove_one<T: Component>(&mut self, ent: Entity)
pub fn remove_one<T: Component>(&mut self, ent: Entity)
Remove a component from entity if it exists
See remove.
Sourcepub fn queue(&mut self, f: impl FnOnce(&mut Substrate) + Send + Sync + 'static)
pub fn queue(&mut self, f: impl FnOnce(&mut Substrate) + Send + Sync + 'static)
Queue an arbitrary operation to be run on a Substrate
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 Substrate::reserve_entity with
insert instead.