From 68c481ecb599c5dbfa1cb516d710d11bd3f2ec99 Mon Sep 17 00:00:00 2001 From: AlephCubed Date: Thu, 12 Mar 2026 21:17:18 -0700 Subject: [PATCH] Improve insert mode performance. --- src/bundle_inspector.rs | 5 ++++- src/command.rs | 9 +++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bundle_inspector.rs b/src/bundle_inspector.rs index c96dbf8..49f2eaf 100644 --- a/src/bundle_inspector.rs +++ b/src/bundle_inspector.rs @@ -1,5 +1,6 @@ use crate::EffectMode; use bevy_ecs::prelude::{Bundle, Entity, Name, Resource, World}; +use bevy_ecs::relationship::RelationshipHookMode; #[derive(Resource)] pub(crate) struct BundleInspector { @@ -21,7 +22,9 @@ impl Default for BundleInspector { impl BundleInspector { pub fn get_effect_meta(&mut self, bundle: B) -> (Option, EffectMode) { let e = self.scratch_entity; - self.world.entity_mut(e).insert(bundle); + self.world + .entity_mut(e) + .insert_with_relationship_hook_mode(bundle, RelationshipHookMode::Skip); let name = self.world.entity(e).get::().cloned(); diff --git a/src/command.rs b/src/command.rs index 777a7e0..f94a1b3 100644 --- a/src/command.rs +++ b/src/command.rs @@ -96,10 +96,7 @@ impl Command for AddEffectCommand { return; } - let Some(effected_by) = world - .get::(self.target) - .map(|e| e.collection().clone()) - else { + let Some(effected_by) = world.get::(self.target).map(|e| e.collection()) else { world.spawn(self.bundle_full()); return; }; @@ -117,7 +114,7 @@ impl Command for AddEffectCommand { let other_name = world.get::(*entity); - if name == other_name.cloned() { + if name.as_ref() == other_name { return Some(*entity); } @@ -132,7 +129,7 @@ impl Command for AddEffectCommand { match mode { EffectMode::Stack => unreachable!(), EffectMode::Insert => { - world.entity_mut(old_entity).insert(self.bundle_full()); + world.entity_mut(old_entity).insert(self.bundle); } EffectMode::Merge => self.merge(world, old_entity), } -- 2.51.2