File tree 1 file changed +24
-0
lines changed
crates/bevy_ecs/src/observer
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1160,4 +1160,28 @@ 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
+ // Observe the removal of A - this will run during despawn
1169
+ world. observe ( |_: Trigger < OnRemove , A > , mut cmd : Commands | {
1170
+ // Spawn a new entity - this reserves a new ID and requires a flush
1171
+ // afterward before Entities::free can be called.
1172
+ cmd. spawn_empty ( ) ;
1173
+ } ) ;
1174
+
1175
+ world. flush ( ) ;
1176
+
1177
+ let ent = world. spawn ( A ) . id ( ) ;
1178
+
1179
+ world. flush ( ) ;
1180
+
1181
+ // Despawn our entity, which runs the OnRemove observer and allocates a
1182
+ // new Entity.
1183
+ world. despawn ( ent) ;
1184
+
1185
+ world. flush ( ) ;
1186
+ }
1163
1187
}
You can’t perform that action at this time.
0 commit comments