Skip to content

Commit 9cdc75d

Browse files
committed
bevy_ecs: add failing test for spawn-in-despawn-observer
1 parent de3c70a commit 9cdc75d

File tree

1 file changed

+24
-0
lines changed
  • crates/bevy_ecs/src/observer

1 file changed

+24
-0
lines changed

crates/bevy_ecs/src/observer/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,4 +1160,28 @@ mod tests {
11601160
world.flush();
11611161
assert_eq!(vec!["event", "event"], world.resource::<Order>().0);
11621162
}
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+
}
11631187
}

0 commit comments

Comments
 (0)