Skip to content

Commit

Permalink
Update GlobalTransform on insertion (#9081)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Shatur authored and cart committed Aug 10, 2023
1 parent 8ba9571 commit 25c64ec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/bevy_transform/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::components::{GlobalTransform, Transform};
use bevy_ecs::{
change_detection::Ref,
prelude::{Changed, DetectChanges, Entity, Query, With, Without},
query::{Added, Or},
removal_detection::RemovedComponents,
system::{Local, ParamSet},
};
Expand All @@ -14,7 +15,11 @@ pub fn sync_simple_transforms(
mut query: ParamSet<(
Query<
(&Transform, &mut GlobalTransform),
(Changed<Transform>, Without<Parent>, Without<Children>),
(
Or<(Changed<Transform>, Added<GlobalTransform>)>,
Without<Parent>,
Without<Children>,
),
>,
Query<(Ref<Transform>, &mut GlobalTransform), Without<Children>>,
)>,
Expand All @@ -31,7 +36,7 @@ pub fn sync_simple_transforms(
let mut query = query.p1();
let mut iter = query.iter_many_mut(orphaned.iter());
while let Some((transform, mut global_transform)) = iter.fetch_next() {
if !transform.is_changed() {
if !transform.is_changed() && !global_transform.is_added() {
*global_transform = GlobalTransform::from(*transform);
}
}
Expand All @@ -56,7 +61,7 @@ pub fn propagate_transforms(
orphaned_entities.sort_unstable();
root_query.par_iter_mut().for_each_mut(
|(entity, children, transform, mut global_transform)| {
let changed = transform.is_changed() || orphaned_entities.binary_search(&entity).is_ok();
let changed = transform.is_changed() || global_transform.is_added() || orphaned_entities.binary_search(&entity).is_ok();
if changed {
*global_transform = GlobalTransform::from(*transform);
}
Expand Down Expand Up @@ -143,7 +148,7 @@ unsafe fn propagate_recursive(
return;
};

changed |= transform.is_changed();
changed |= transform.is_changed() || global_transform.is_added();
if changed {
*global_transform = parent.mul_transform(*transform);
}
Expand Down

0 comments on commit 25c64ec

Please sign in to comment.