-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
Commands failing due to an entity being despawned is one of the most common and frustrating sources of panics in Bevy at the moment.
What solution would you like?
- Enable better backtrace behavior to enable debugging. In particular, we need to know the list of other commands that operated on this entity, and which systems they were issued in.
- A tool to enable entity commands to fail gracefully (silently ignore / log / warn) rather than panicking.
What alternative(s) have you considered?
Try
For each of the existing methods on EntityCommands, unwrap this option. Create a try_X variant for each method.
This creates significant API bloat and doesn't capture the way that entity commands are chained: after the first operation has succeeded, the rest of the operations in the chain are infallible.
Verified entity flag
Store a verified_entity_exists Option flag on EntityCommands. Each of the existing methods on EntityCommands should attempt to set this flag by unwrapping it to Some(true) if it is None`, and be skipped if it is false.
Then, create a few methods on EntityCommands that set the value of the verification flag with varying behavior:
commands.entity(entity).silently_fail_if_missing().insert(Foo)commands.entity(entity).log_if_missing().insert(Foo)commands.entity(entity).warn_if_missing().insert(Foo)
This doesn't work though, because the check is occuring at command-issuing time.
Additional context
#2241 proposes a much more general approach to this, but has significant complexity and overhead.
#3757 aims for a similar goal, but doesn't actually create a reliable API: entities can be despawned after we check for their existence, resulting in the same panic.