-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to use
Description
Bevy version
0.9.1
What went wrong
These two systems look innocent on their own, but may cause panic if used together.
fn insert(mut commands: Commands, query: Query<Entity, With<Marker>>, ...) {
for entity in query.iter() {
if ... {
// We obtained the entity from the query, so it must be valid, right?
commands.entity(entity).insert(Foo);
}
}
}
fn despawn(mut commands: Commands, query: Query<Entity, With<Marker>>, ...) {
for entity in query.iter() {
if ... {
// This command may execute before the insertion and cause a panic there!
commands.entity(entity).despawn();
}
}
}
This panic is hard to avoid in user code, as there is no way to know if there is a pending despawn command for a certain entity.
Additional information
The Insert command is, as far as I know, the only place where a missing entity in command execution is turned into a panic. We should at least replace the panic with a soft error or warning like the other commands.
We are also currently inconsistent in the way missing entities are reported. Insert uses panics, Remove uses no error reporting at all (we may want to change this), Despawn uses warnings, and DespawnRecursive use debug messages.
SludgePhD, XelfXendr, fennifith, JeanMertz, schneiderfelipe and 1 more
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to use