bevy: thread 'main' panicked at 'Entity does not exist'
Bevy version
47004dfc)
Operating system & version
Windows 10
What you did
I have a system that adds/removes unit struct components via Commands
. Sometimes my game runs fine for several minutes before crashing. Others, it crashes quickly with this panic:
panic: thread ‘main’ panicked at ‘Entity does not exist’
The full log of my run, with Bevy set to debug mode and the system ambiguity checker added, can be found here. I can’t pin down an easy reproduction even in my own game–it just seems like things crash after a while and I don’t know why. If I’m tracing the panic back correctly to the system in question, it isn’t immediately obvious to me that it’s accessing despawned entities.
I’m seeing lots of this in the log:
[2mMar 24 10:46:27.784[0m [34mDEBUG[0m bevy_ecs::system::commands: Failed to despawn non-existent entity 271v1
I’m not sure where this is happening, but this is logging on debug. I’m also not sure how to trace back from this failing command invocation, to whatever system originated it. Obviously I want to do something about these failed despawns–I just don’t know how.
What you expected to happen
Not panicking would be nice. as would some mechanism for tracing back from the panic to the specific command that caused it. Maybe some sort of no-op remove (I.e. “remove this component, but don’t panic if the entity doesn’t exist”) would be nice too, though maybe I’m hitting a soundness bug somewhere that shouldn’t be papered over by no-op commands. 😃
What actually happened
Panics at random times. It’s always when interacting with a specific subsystem of my game, but never in response to a specific action type or at a transition point.
Additional information
Happy to provide any, just let me know how to turn logging up to 11. 😃
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (17 by maintainers)
#846 may be relevant here.
With the new ordering of systems, this would be even more useful
Sorry, I’m fine with pushing this past 0.5, but there’s a workaround? I’m not clear on what it is. I seem to be despawning a bunch of entities that I have no way of knowing where they were spawned, and I don’t know what to reorder much less which order to put things in. This does seem to be a bit of a corner case, so by all means don’t delay the release, but if a workaround for my current situation was mentioned here, I must not be smart enough to have spotted it. 😃 Is the workaround just to brute-force reorder systems touching this particular component until my crashes stop?
Thanks.
Im thinking this this issue isn’t really something we can solve in the next day (and system ordering/restructuring logic is a workaround), so I’m removing this from the 0.5 milestone. We can add it back if thats unpopular or if I missed something important.
Ugh, I’m now relying on reliable change detection, so I can’t revert that. I’ll wait for a fix. and see if this goes away.
But something similar happened on 0.4, so it’s possible these are different issues. I didn’t log because I’d hoped the ECS rewrite would nuke it from orbit, but the behavior is the same.