Skip to content

Commit c71ae26

Browse files
authored
Update GlobalTransform on insertion (#9081)
# Objective `GlobalTransform` after insertion will be updated only on `Transform` or hierarchy change. Fixes #9075 ## Solution Update `GlobalTransform` after insertion too. --- ## Changelog - `GlobalTransform` is now updated not only on `Transform` or hierarchy change, but also on insertion.
1 parent ffc5727 commit c71ae26

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/bevy_transform/src/systems.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::components::{GlobalTransform, Transform};
22
use bevy_ecs::{
33
change_detection::Ref,
44
prelude::{Changed, DetectChanges, Entity, Query, With, Without},
5+
query::{Added, Or},
56
removal_detection::RemovedComponents,
67
system::{Local, ParamSet},
78
};
@@ -14,7 +15,11 @@ pub fn sync_simple_transforms(
1415
mut query: ParamSet<(
1516
Query<
1617
(&Transform, &mut GlobalTransform),
17-
(Changed<Transform>, Without<Parent>, Without<Children>),
18+
(
19+
Or<(Changed<Transform>, Added<GlobalTransform>)>,
20+
Without<Parent>,
21+
Without<Children>,
22+
),
1823
>,
1924
Query<(Ref<Transform>, &mut GlobalTransform), Without<Children>>,
2025
)>,
@@ -31,7 +36,7 @@ pub fn sync_simple_transforms(
3136
let mut query = query.p1();
3237
let mut iter = query.iter_many_mut(orphaned.iter());
3338
while let Some((transform, mut global_transform)) = iter.fetch_next() {
34-
if !transform.is_changed() {
39+
if !transform.is_changed() && !global_transform.is_added() {
3540
*global_transform = GlobalTransform::from(*transform);
3641
}
3742
}
@@ -56,7 +61,7 @@ pub fn propagate_transforms(
5661
orphaned_entities.sort_unstable();
5762
root_query.par_iter_mut().for_each_mut(
5863
|(entity, children, transform, mut global_transform)| {
59-
let changed = transform.is_changed() || orphaned_entities.binary_search(&entity).is_ok();
64+
let changed = transform.is_changed() || global_transform.is_added() || orphaned_entities.binary_search(&entity).is_ok();
6065
if changed {
6166
*global_transform = GlobalTransform::from(*transform);
6267
}
@@ -143,7 +148,7 @@ unsafe fn propagate_recursive(
143148
return;
144149
};
145150

146-
changed |= transform.is_changed();
151+
changed |= transform.is_changed() || global_transform.is_added();
147152
if changed {
148153
*global_transform = parent.mul_transform(*transform);
149154
}

0 commit comments

Comments
 (0)