From 7048e01ceb3aaaea35dcfe0b324c3ca146e1856f Mon Sep 17 00:00:00 2001 From: eugineerd Date: Wed, 9 Jul 2025 19:53:30 +0000 Subject: [PATCH] avoid copying when `deferred_clone_component_ids` is empty --- crates/bevy_ecs/src/entity/clone_entities.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index 5df3658d3f..ee2b30ba7f 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -661,8 +661,12 @@ impl EntityCloner { let mut source_entity = world.entity_mut(source); // Remove all cloned components with drop by concatenating both vectors - deferred_cloned_component_ids.extend(&bundle_scratch.component_ids); - source_entity.remove_by_ids(&deferred_cloned_component_ids); + if deferred_cloned_component_ids.is_empty() { + source_entity.remove_by_ids(&bundle_scratch.component_ids); + } else { + deferred_cloned_component_ids.extend(&bundle_scratch.component_ids); + source_entity.remove_by_ids(&deferred_cloned_component_ids); + } let table_row = source_entity.location().table_row;