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 @@ -1160,4 +1160,22 @@ mod tests {
1160
1160
world. flush ( ) ;
1161
1161
assert_eq ! ( vec![ "event" , "event" ] , world. resource:: <Order >( ) . 0 ) ;
1162
1162
}
1163
+
1164
+ #[ test]
1165
+ fn observer_on_remove_during_despawn_spawn_empty ( ) {
1166
+ let mut world = World :: new ( ) ;
1167
+
1168
+ let ent = world
1169
+ . spawn ( A )
1170
+ . observe ( |trigger : Trigger < OnRemove , A > , mut cmd : Commands | {
1171
+ cmd. spawn_empty ( ) ;
1172
+ } )
1173
+ . id ( ) ;
1174
+
1175
+ world. flush ( ) ;
1176
+
1177
+ world. entity_mut ( ent) . despawn ( ) ;
1178
+
1179
+ world. flush ( ) ;
1180
+ }
1163
1181
}
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