From d5461ba0146063567eeee445ac3e9e5be0aac5bd Mon Sep 17 00:00:00 2001 From: Kao-Wei Yeh Date: Wed, 13 May 2026 00:14:17 +0800 Subject: [PATCH] Add new method `entity_commands` to `EntityWorldMut` --- crates/bevy_ecs/src/world/entity_access/world_mut.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/bevy_ecs/src/world/entity_access/world_mut.rs b/crates/bevy_ecs/src/world/entity_access/world_mut.rs index d77a26315b30f..8f4d9010ba9f7 100644 --- a/crates/bevy_ecs/src/world/entity_access/world_mut.rs +++ b/crates/bevy_ecs/src/world/entity_access/world_mut.rs @@ -16,6 +16,7 @@ use crate::{ relationship::RelationshipHookMode, resource::Resource, storage::{SparseSets, Table}, + system::EntityCommands, template::{EntityScopes, ScopedEntities, Template, TemplateContext}, world::{ error::EntityComponentError, unsafe_world_cell::UnsafeEntityCell, ComponentEntry, @@ -1877,6 +1878,17 @@ impl<'w> EntityWorldMut<'w> { f(guard.entity_mut.world) } + /// Creates a new [`EntityCommands`] instance that writes to the world's command queue + /// Use [`World::flush`] to apply all queued commands + #[inline] + pub fn entity_commands(&mut self) -> EntityCommands<'_> { + let id = self.id(); + EntityCommands { + entity: id, + commands: self.world.commands(), + } + } + /// Updates the internal entity location to match the current location in the internal /// [`World`]. ///