diff --git a/crates/bevy_ui/src/flex/mod.rs b/crates/bevy_ui/src/flex/mod.rs index 7d3d9acde54c5a..cda1167e7446c4 100644 --- a/crates/bevy_ui/src/flex/mod.rs +++ b/crates/bevy_ui/src/flex/mod.rs @@ -278,17 +278,22 @@ pub fn flex_node_system( to_logical(layout.size.width), to_logical(layout.size.height), ); + // only trigger change detection when the new value is different if node.size != new_size { node.size = new_size; } - let position = &mut transform.translation; - position.x = to_logical(layout.location.x + layout.size.width / 2.0); - position.y = to_logical(layout.location.y + layout.size.height / 2.0); + let mut new_position = transform.translation; + new_position.x = to_logical(layout.location.x + layout.size.width / 2.0); + new_position.y = to_logical(layout.location.y + layout.size.height / 2.0); if let Some(parent) = parent { if let Ok(parent_layout) = flex_surface.get_layout(parent.0) { - position.x -= to_logical(parent_layout.size.width / 2.0); - position.y -= to_logical(parent_layout.size.height / 2.0); + new_position.x -= to_logical(parent_layout.size.width / 2.0); + new_position.y -= to_logical(parent_layout.size.height / 2.0); } } + // only trigger change detection when the new value is different + if transform.translation != new_position { + transform.translation = new_position; + } } } diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index 9fe0fc446e345c..9fe53009b93a00 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -45,7 +45,11 @@ fn update_hierarchy( ) -> f32 { current_global_z += UI_Z_STEP; if let Ok(mut transform) = node_query.get_mut(entity) { - transform.translation.z = current_global_z - parent_global_z; + let new_z = current_global_z - parent_global_z; + // only trigger change detection when the new value is different + if transform.translation.z != new_z { + transform.translation.z = new_z; + } } if let Ok(children) = children_query.get(entity) { let current_parent_global_z = current_global_z;