From 2667dd1f08c814f0f3b68a898db6e03d30e7a41f Mon Sep 17 00:00:00 2001 From: eugineerd Date: Wed, 9 Jul 2025 17:05:16 +0000 Subject: [PATCH] Skip all cloning logic for `ComponentCloneBehavior::Ignore` --- crates/bevy_ecs/src/entity/clone_entities.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/bevy_ecs/src/entity/clone_entities.rs b/crates/bevy_ecs/src/entity/clone_entities.rs index 86bf59e94b..795566b7d5 100644 --- a/crates/bevy_ecs/src/entity/clone_entities.rs +++ b/crates/bevy_ecs/src/entity/clone_entities.rs @@ -589,13 +589,18 @@ impl EntityCloner { } filter.clone_components(source_archetype, target_archetype, |component| { - let handler = match state.clone_behavior_overrides.get(&component) { - Some(clone_behavior) => clone_behavior.resolve(state.default_clone_fn), - None => world + let handler = match state.clone_behavior_overrides.get(&component).or_else(|| { + world .components() .get_info(component) - .map(|info| info.clone_behavior().resolve(state.default_clone_fn)) - .unwrap_or(state.default_clone_fn), + .map(ComponentInfo::clone_behavior) + }) { + Some(behavior) => match behavior { + ComponentCloneBehavior::Default => state.default_clone_fn, + ComponentCloneBehavior::Ignore => return, + ComponentCloneBehavior::Custom(custom) => *custom, + }, + None => state.default_clone_fn, }; // SAFETY: This component exists because it is present on the archetype.