-
-
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
Despawning entities should silently fail if the entity does not exist #5617
Comments
I'm very against commands silently failing. While it's not an issue in the case of despawn, it still means the game is not in the state expected by the system (an entity has already been despawned when the system thought it was still present) and so could hide a bigger bug in the user code. Letting the user choose to ignore it could be good, but the default must be to panic |
Could warning instead silently fail be a less controvertial alternative to this? |
IMO the correct level would be |
Not for me at least 🤷 For log level, I guess at least warning. Anyway it wouldn't surface in a released game because the log levels would have been appropriately set to not surface bevy logs as they aren't relevant. |
Another approach would be to keep the existing The documentation for |
That would increase the API complexity for no actual benefit. Why would someone use In the case of a user always using IMO the best we can do is leave things as is (panicking is not a big issue, you fix the bug and you go), or you get a warning (app still goes, so you can continue to develop/debug, but you get a reminder that you have to fix it). |
I agree with others. When I call |
If people want it to silently fail, they can already use Another approach would be for |
That's useful data about the behaviour of World::despawn. Proper result-based error handling for Commands is very high up on my list of "critical problems that need fixing", but the design is nontrivial due to the deferred nature of the work. |
If commands were able to return anything about their execution that would be great, but commands are executed only once the system is finished... |
I don't see how adding a |
I think despawn should not panic by default since the default parallel nature of Bevy makes it hard to reason and verify the timeline of entity lifetimes (not Rust lifetimes) regardless unless you go all in planning your world sync points carefully, which I personally don't do if I can get away with it. By getting away with it I mean that most of the ECS code is written to update entities and their components when they exist and are ready to be updated, otherwise the code just does something else or nothing while waiting for the entities to appear (which can happen whenever). |
Despawn no longer panics, but it does warn (which I think it shouldn't). These logs are super noisy with state scoped entities as well. |
In favor argument for no panic/silence. |
I'm getting a lot of these warnings, but I'm not quite sure why. I have a system with an argument for entity in query.iter() {
commands.entity(entity).despawn_recursive()
} My only though is that I might be overflowing the entity ID space? |
If you're querying for multiple entities per tree, many of the children will be despawned by the time the corresponding trees are processed. |
I get it without |
Hello! Anyone has a good practice to get rid of this warning? I've been working around this for several hours and can't really find a solution. In my case, the bullet in the game despawns both after hitting an enemy and after reaching its own lifespan. i printed the entity id in two separate systems and it became apparent that it was both systems attempting to despawn the same entity that caused this warning. |
Writing your own custom despawn command is easy, and this warning won't occur simply when calling |
took a look at the source code and i think world.despawn still raises the warning: #[inline]
pub fn despawn(&mut self, entity: Entity) -> bool {
self.flush();
if let Some(entity) = self.get_entity_mut(entity) {
entity.despawn();
true
} else {
warn!("error[B0003]: Could not despawn entity {:?} because it doesn't exist in this World. See: https://bevyengine.org/learn/errors/#b0003", entity);
false
}
} but i did this and it worked: commands.add(move |world: &mut World| {
if let Some(entity) = world.get_entity_mut(e) {
entity.despawn();
}
}); Thanks!
|
What problem does this solve or what need does it fill?
Panics when working with commands are extremely frustrating, and difficult to debug or guard against.
What solution would you like?
We can reduce the pain in the common case by making
commands.entity(my_entity).despawn()
fail silently if the entity does not exist.There is no real risk to doing so, as the desired state is completed. This is also useful as it makes despawn commands idempotent, making them significantly more robust and easier to work with.
What alternative(s) have you considered?
#2004 represents a more complete solution, but is dramatically more complex. This is also a better default for this particular command.
Additional context
We may also want to change the behavior of other commands, but that should be done in separate PRs to avoid blocking this less controversial change.
The text was updated successfully, but these errors were encountered: