File tree 2 files changed +22
-0
lines changed
2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -1082,4 +1082,22 @@ mod tests {
1082
1082
world. flush ( ) ;
1083
1083
assert_eq ! ( vec![ "event" , "event" ] , world. resource:: <Order >( ) . 0 ) ;
1084
1084
}
1085
+
1086
+ #[ test]
1087
+ fn observer_on_remove_during_despawn_spawn_empty ( ) {
1088
+ let mut world = World :: new ( ) ;
1089
+
1090
+ let ent = world
1091
+ . spawn ( A )
1092
+ . observe ( |trigger : Trigger < OnRemove , A > , mut cmd : Commands | {
1093
+ cmd. spawn_empty ( ) ;
1094
+ } )
1095
+ . id ( ) ;
1096
+
1097
+ world. flush ( ) ;
1098
+
1099
+ world. entity_mut ( ent) . despawn ( ) ;
1100
+
1101
+ world. flush ( ) ;
1102
+ }
1085
1103
}
Original file line number Diff line number Diff line change @@ -1319,6 +1319,10 @@ impl<'w> EntityWorldMut<'w> {
1319
1319
}
1320
1320
}
1321
1321
1322
+ // Observers and on_remove hooks may reserve new entities, which
1323
+ // requires a flush before Entities::free may be called.
1324
+ world. flush_entities ( ) ;
1325
+
1322
1326
for component_id in archetype. components ( ) {
1323
1327
world. removed_components . send ( component_id, self . entity ) ;
1324
1328
}
You can’t perform that action at this time.
0 commit comments