diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index 90adfb8dc510c..e25bc2313fcb4 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -338,7 +338,9 @@ where T: Bundle + 'static, { fn write(self: Box, world: &mut World) { - world.entity_mut(self.entity).insert_bundle(self.bundle); + if let Some(mut entity_mut) = world.get_entity_mut(self.entity) { + entity_mut.insert_bundle(self.bundle); + } } } @@ -353,7 +355,9 @@ where T: Component, { fn write(self: Box, world: &mut World) { - world.entity_mut(self.entity).insert(self.component); + if let Some(mut entity_mut) = world.get_entity_mut(self.entity) { + entity_mut.insert(self.component); + } } }