From 76d405f8a05b186d08687e929d6462da7f2d729b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Thu, 22 Oct 2020 21:27:55 +0200 Subject: [PATCH] do not use slower fallback when issue is that entity doesn't exist --- crates/bevy_ecs/src/system/commands.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/crates/bevy_ecs/src/system/commands.rs b/crates/bevy_ecs/src/system/commands.rs index 4daf76d3d890ec..e36de7ef78b5a4 100644 --- a/crates/bevy_ecs/src/system/commands.rs +++ b/crates/bevy_ecs/src/system/commands.rs @@ -126,13 +126,23 @@ where T: Bundle + Send + Sync + 'static, { fn write(self: Box, world: &mut World, _resources: &mut Resources) { - if let Err(e) = world.remove::(self.entity) { - log::warn!( - "Failed to remove components {:?} with error: {}. Falling back to inefficient one-by-one component removing.", - std::any::type_name::(), - e - ); - if let Err(e) = world.remove_one_by_one::(self.entity) { + match world.remove::(self.entity) { + Ok(_) => (), + Err(bevy_hecs::ComponentError::MissingComponent(e)) => { + log::warn!( + "Failed to remove components {:?} with error: {}. Falling back to inefficient one-by-one component removing.", + std::any::type_name::(), + e + ); + if let Err(e) = world.remove_one_by_one::(self.entity) { + log::debug!( + "Failed to remove components {:?} with error: {}", + std::any::type_name::(), + e + ); + } + } + Err(e) => { log::debug!( "Failed to remove components {:?} with error: {}", std::any::type_name::(),