Skip to content

Commit

Permalink
do not use slower fallback when issue is that entity doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Oct 30, 2020
1 parent 863d70e commit 76d405f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions crates/bevy_ecs/src/system/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,23 @@ where
T: Bundle + Send + Sync + 'static,
{
fn write(self: Box<Self>, world: &mut World, _resources: &mut Resources) {
if let Err(e) = world.remove::<T>(self.entity) {
log::warn!(
"Failed to remove components {:?} with error: {}. Falling back to inefficient one-by-one component removing.",
std::any::type_name::<T>(),
e
);
if let Err(e) = world.remove_one_by_one::<T>(self.entity) {
match world.remove::<T>(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::<T>(),
e
);
if let Err(e) = world.remove_one_by_one::<T>(self.entity) {
log::debug!(
"Failed to remove components {:?} with error: {}",
std::any::type_name::<T>(),
e
);
}
}
Err(e) => {
log::debug!(
"Failed to remove components {:?} with error: {}",
std::any::type_name::<T>(),
Expand Down

0 comments on commit 76d405f

Please sign in to comment.