-
I'm trying to despawn specific entities when they collide. bevy_xpbd seems to rely on component removal detection and so I was wondering how to do what I want reliably. I tried the following : // In my setup code
app.add_systems( // Add a hard sync point to trigger component removal events
(on_collision, apply_system_buffers)
.chain()
// Run before the physics step so that it has a chance to see the component removals
.before(PhysicsSet::Prepare),
);
// We always read collision events the frame after they are sent but that's not really a problem
fn on_collision(
mut evt_reader: EventReader<Collision>,
mut commands: Commands,
query: Query<AnyOf<(&Player, &Bullet)>>,
) {
for Collision(contact) in evt_reader.iter() {
debug!(?contact.entity1, ?contact.entity2);
if let (Ok((_, bullet1)), Ok((_, bullet2))) =
(query.get(contact.entity1), query.get(contact.entity2))
{
if bullet1.is_some() {
commands.entity(contact.entity1).despawn();
}
if bullet2.is_some() {
commands.entity(contact.entity2).despawn();
}
}
}
} But I get non-deterministic results, and the app crashes. Relevant part of the stack trace :
It seems |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I can't reproduce the error when trying to despawn entities on contact in an example similar to the [dependencies]
bevy_xpbd_3d = { git = "https://github.com/Jondolf/bevy_xpbd.git" } # or 2D The fix will be in 0.2, which will release after Bevy 0.11. Let me know if it works or if there are other issues. |
Beta Was this translation helpful? Give feedback.
I can't reproduce the error when trying to despawn entities on contact in an example similar to the
cubes
example, but I removed theunwrap
call to avoid panicking when the entity is missing. Could you try your example on the main branch? Specify the dependency like this:The fix will be in 0.2, which will release after Bevy 0.11. Let me know if it works or if there are other issues.