Skip to content

EntityCommands should have methods to fail gracefully #3845

@alice-i-cecile

Description

@alice-i-cecile

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?

  1. 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.
  2. 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:

  1. commands.entity(entity).silently_fail_if_missing().insert(Foo)
  2. commands.entity(entity).log_if_missing().insert(Foo)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions