From 05f293be246b64c44130a1e6a9504a4cdc604dd4 Mon Sep 17 00:00:00 2001 From: Ashley Ruglys Date: Sun, 23 May 2021 15:53:42 +0200 Subject: [PATCH] use get_entity_mut in insert commands to avoid a panic --- crates/bevy_ecs/src/system/commands.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); + } } }