pub struct CommandBuffer { /* private fields */ }
Expand description
A buffer of deferred ECS commands such as entity creation, component addition/removal, and destruction.
This is useful for queuing up changes during system execution to avoid mutably borrowing the world
while it’s being accessed elsewhere. Changes can be applied all at once using CommandBuffer::execute
.
§Fields
commands
: The queued operations to apply.
§Safety
- Commands are applied with exclusive access to the
World
to ensure memory safety.
Implementations§
Source§impl CommandBuffer
impl CommandBuffer
Sourcepub fn create_entity(&mut self)
pub fn create_entity(&mut self)
Queues a command to create a new entity in the world.
The entity will be returned by execute
when the command is applied.
Sourcepub fn destroy_entity(&mut self, entity: Entity)
pub fn destroy_entity(&mut self, entity: Entity)
Queues a command to destroy an entity. This will remove all of its components and make its ID reusable.
§Parameters
entity
: The entity to be destroyed.
Sourcepub fn add_component<T: Component + Send + 'static>(
&mut self,
entity: Entity,
component: T,
)
pub fn add_component<T: Component + Send + 'static>( &mut self, entity: Entity, component: T, )
Sourcepub fn remove_component<T: Component + 'static>(&mut self, entity: Entity)
pub fn remove_component<T: Component + 'static>(&mut self, entity: Entity)
Sourcepub fn create_entity_and_add_component<T: Component + Send + 'static>(
&mut self,
component: T,
)
pub fn create_entity_and_add_component<T: Component + Send + 'static>( &mut self, component: T, )
Trait Implementations§
Source§impl Default for CommandBuffer
impl Default for CommandBuffer
Source§fn default() -> CommandBuffer
fn default() -> CommandBuffer
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for CommandBuffer
impl !RefUnwindSafe for CommandBuffer
impl !Send for CommandBuffer
impl !Sync for CommandBuffer
impl Unpin for CommandBuffer
impl !UnwindSafe for CommandBuffer
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