diff --git a/crates/bevy_transform/src/systems.rs b/crates/bevy_transform/src/systems.rs index 9fb2e9a2d0..bc40d58bb6 100644 --- a/crates/bevy_transform/src/systems.rs +++ b/crates/bevy_transform/src/systems.rs @@ -1,7 +1,8 @@ use crate::components::{GlobalTransform, Transform}; use bevy_ecs::{ entity::Entity, - query::{Changed, With, Without}, + prelude::Changed, + query::{With, Without}, system::Query, }; use bevy_hierarchy::{Children, Parent}; @@ -10,16 +11,23 @@ use bevy_hierarchy::{Children, Parent}; /// [`Transform`] component. pub fn transform_propagate_system( mut root_query: Query< - (Entity, Option<&Children>, &Transform, &mut GlobalTransform), + ( + Option<&Children>, + &Transform, + Changed, + &mut GlobalTransform, + ), Without, >, - mut transform_query: Query<(&Transform, &mut GlobalTransform), With>, - changed_transform_query: Query>, + mut transform_query: Query< + (&Transform, Changed, &mut GlobalTransform), + With, + >, children_query: Query, (With, With)>, ) { - for (entity, children, transform, mut global_transform) in root_query.iter_mut() { + for (children, transform, transform_changed, mut global_transform) in root_query.iter_mut() { let mut changed = false; - if changed_transform_query.get(entity).is_ok() { + if transform_changed { *global_transform = GlobalTransform::from(*transform); changed = true; } @@ -28,7 +36,6 @@ pub fn transform_propagate_system( for child in children.iter() { propagate_recursive( &global_transform, - &changed_transform_query, &mut transform_query, &children_query, *child, @@ -41,16 +48,19 @@ pub fn transform_propagate_system( fn propagate_recursive( parent: &GlobalTransform, - changed_transform_query: &Query>, - transform_query: &mut Query<(&Transform, &mut GlobalTransform), With>, + transform_query: &mut Query< + (&Transform, Changed, &mut GlobalTransform), + With, + >, children_query: &Query, (With, With)>, entity: Entity, mut changed: bool, ) { - changed |= changed_transform_query.get(entity).is_ok(); - let global_matrix = { - if let Ok((transform, mut global_transform)) = transform_query.get_mut(entity) { + if let Ok((transform, transform_changed, mut global_transform)) = + transform_query.get_mut(entity) + { + changed |= transform_changed; if changed { *global_transform = parent.mul_transform(*transform); } @@ -64,7 +74,6 @@ fn propagate_recursive( for child in children.iter() { propagate_recursive( &global_matrix, - changed_transform_query, transform_query, children_query, *child,