From f8cac5749511d6e0a5356264a9e3f0e3501a92b7 Mon Sep 17 00:00:00 2001 From: Anthony Tornetta Date: Mon, 21 Oct 2024 15:00:18 -0400 Subject: [PATCH] #592 Adding change check before setting position This prevents excess work from being done in step_simulation --- src/plugin/systems/collider.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugin/systems/collider.rs b/src/plugin/systems/collider.rs index f3edc0be..9d44ee41 100644 --- a/src/plugin/systems/collider.rs +++ b/src/plugin/systems/collider.rs @@ -122,10 +122,22 @@ pub fn apply_collider_user_changes( collider_offset(entity, &context, &parent_query, &transform_query); if let Some(co) = context.colliders.get_mut(handle.0) { - co.set_position_wrt_parent(utils::transform_to_iso(&collider_position)); + let new_pos = utils::transform_to_iso(&collider_position); + + if co + .position_wrt_parent() + .map(|pos| *pos != new_pos) + .unwrap_or(true) + { + co.set_position_wrt_parent(new_pos); + } } } else if let Some(co) = context.colliders.get_mut(handle.0) { - co.set_position(utils::transform_to_iso(&transform.compute_transform())) + let new_pos = utils::transform_to_iso(&transform.compute_transform()); + + if *co.position() != new_pos { + co.set_position(utils::transform_to_iso(&transform.compute_transform())); + } } }