Skip to content
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

StateScoped entity could cause "Could not despawn entity" warning #15212

Open
Shatur opened this issue Sep 15, 2024 · 3 comments
Open

StateScoped entity could cause "Could not despawn entity" warning #15212

Shatur opened this issue Sep 15, 2024 · 3 comments
Labels
A-States App-level states machines C-Bug An unexpected or incorrect behavior

Comments

@Shatur
Copy link
Contributor

Shatur commented Sep 15, 2024

Bevy version

v0.14.2

What you did

I spawned an entity with StateScoped(MyState) component and a children with StateScoped(MySubState) component.

What went wrong

If I exit MyState, both entities will first be despawned by StateScoped(MyState) (due to recursive despawn), and then the child entity will also be attempted to be despawned by StateScoped(MySubState). It causes warning:

WARN bevy_ecs::world: error[B0003]: Could not despawn entity because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/#

I think that the warning shouldn't be emitted in this case.

@Shatur Shatur added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Sep 15, 2024
@benfrankel
Copy link
Contributor

benfrankel commented Sep 16, 2024

IMO the warning shouldn't be emitted in general, but I won't try to argue for that here. Some other options:

  1. Add a try_despawn_recursive command that accepts that the entity may not exist when the command runs, so it doesn't warn.
  2. Rebrand StateScoped as enum DespawnOnExit { Single, Descendants, Recursive } so it's more obvious that it does a recursive despawn and you only need to attach it to the root entity.
  3. Make no change and consider this a user error, where they shouldn't be putting StateScoped on both parent and child.

@Shatur
Copy link
Contributor Author

Shatur commented Sep 16, 2024

Yeah, I agree that it shouldn't be a warning.

@alice-i-cecile alice-i-cecile added A-States App-level states machines and removed S-Needs-Triage This issue needs to be labelled labels Sep 16, 2024
@alice-i-cecile
Copy link
Member

Broader issue is #5617.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-States App-level states machines C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

3 participants