-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EntityCommands should have methods to fail gracefully #3845
Comments
The critical challenge here is that we need to check evaluation at the time of Command evaluation, not command issuing. |
I tried to solve this with:
As said on discord, I dislike this option as I worry people would jump on ignoring failures instead of fixing their system ordering, potentially leaving their game in an unexpected state |
I want to respectfully push back against this idea, or at least my perception of this idea, that those of us experiencing this just need to reorder our systems already. :) There really aren't any good tools for doing this at scale, without introducing all sorts of brittle cross-plugin dependencies. So say I have a damage/health system that despawns any entities with < 0 damage. That means I...run every single system before this To be clear, I'm fine with methods like |
Some other solutions that might help reduce these problems:
|
in the cases that panics now, there are two commands to apply on the same entity: a despawn, then a component insert. How would it work with refcounting? would it be the despawn that would panic? |
One graceful method ( |
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?
What alternative(s) have you considered?
Try
For each of the existing methods on
EntityCommands
, unwrap this option. Create atry_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 onEntityCommands
. Each of the existing methods onEntityCommands
should attempt to set this flag by unwrapping it toSome(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.
@EmiOnGit expressed interest in this problem in #3840.
The text was updated successfully, but these errors were encountered: