@@ -3,7 +3,7 @@ use bevy_ecs::{
3
3
change_detection:: Ref ,
4
4
prelude:: { Changed , DetectChanges , Entity , Query , With , Without } ,
5
5
removal_detection:: RemovedComponents ,
6
- system:: ParamSet ,
6
+ system:: { Local , ParamSet } ,
7
7
} ;
8
8
use bevy_hierarchy:: { Children , Parent } ;
9
9
@@ -48,12 +48,14 @@ pub fn propagate_transforms(
48
48
mut orphaned : RemovedComponents < Parent > ,
49
49
transform_query : Query < ( Ref < Transform > , & mut GlobalTransform , Option < & Children > ) , With < Parent > > ,
50
50
parent_query : Query < ( Entity , Ref < Parent > ) > ,
51
+ mut orphaned_entities : Local < Vec < Entity > > ,
51
52
) {
52
- let mut orphaned = orphaned. iter ( ) . collect :: < Vec < _ > > ( ) ;
53
- orphaned. sort_unstable ( ) ;
53
+ orphaned_entities. clear ( ) ;
54
+ orphaned_entities. extend ( orphaned. iter ( ) ) ;
55
+ orphaned_entities. sort_unstable ( ) ;
54
56
root_query. par_iter_mut ( ) . for_each_mut (
55
57
|( entity, children, transform, mut global_transform) | {
56
- let changed = transform. is_changed ( ) || orphaned . binary_search ( & entity) . is_ok ( ) ;
58
+ let changed = transform. is_changed ( ) || orphaned_entities . binary_search ( & entity) . is_ok ( ) ;
57
59
if changed {
58
60
* global_transform = GlobalTransform :: from ( * transform) ;
59
61
}
@@ -205,9 +207,10 @@ mod test {
205
207
command_queue. apply ( & mut world) ;
206
208
schedule. run ( & mut world) ;
207
209
208
- assert_ne ! (
210
+ assert_eq ! (
209
211
world. get:: <GlobalTransform >( parent) . unwrap( ) ,
210
- & GlobalTransform :: from( Transform :: IDENTITY )
212
+ & offset_global_transform( 4.4 + 3.3 ) ,
213
+ "The transform systems didn't run, ie: `GlobalTransform` wasn't updated" ,
211
214
) ;
212
215
213
216
// Remove parent of `parent`
@@ -219,7 +222,8 @@ mod test {
219
222
220
223
assert_eq ! (
221
224
world. get:: <GlobalTransform >( parent) . unwrap( ) ,
222
- & offset_global_transform( 4.4 )
225
+ & offset_global_transform( 4.4 ) ,
226
+ "The global transform of an orphaned entity wasn't updated properly" ,
223
227
) ;
224
228
225
229
// Remove parent of `child`
@@ -231,7 +235,8 @@ mod test {
231
235
232
236
assert_eq ! (
233
237
world. get:: <GlobalTransform >( child) . unwrap( ) ,
234
- & offset_global_transform( 5.5 )
238
+ & offset_global_transform( 5.5 ) ,
239
+ "The global transform of an orphaned entity wasn't updated properly" ,
235
240
) ;
236
241
}
237
242
0 commit comments