bevy: Need the OnEnter() and OnExit() to be run even if when transitioning to and from the same state.
What problem does this solve or what need does it fill?
When using bevy 0.10.1, I can trigger a button click event and enter StateA, and query some resources and spawn some bundles when I enter this StateA with add_system(setup.in_schedule(OnEnter(StateA)))
, every time I click the button (without leave the StateA), I can despawn bundles by using add_system(exit.in_schedule(OnExit(StateA)));
and spawn new bundles according to the resources again. But after I update to bevy 0.11, this cannot be done because of #8359.
What solution would you like?
I hope OnEnter
and OnExit
can be run again when the system enters the same state, or at least, can make it optional.
What alternative(s) have you considered?
No effective methods were found.
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 10
- Comments: 27 (21 by maintainers)
Add
OnEachEnter
andOnEachExit
schedules?Made a PR for the system param approach, which I prefer. I’m leaving the
NextState::set_forced
PR open for now.Names are all bikesheddable, I didn’t think too hard about them.
There are use cases for both re-triggering and not re-triggering. See https://github.com/bevyengine/bevy/issues/8191. I don’t know what the overhead of a schedule is in Bevy, but if it’s not significant then both use cases should be easily supported. The docs should be clear on the distinction. I think it’s not really cognitive overhead; the state transition logic maps quite nicely to the schedules.
I think also some more care should be given to changing things as fundamental as this without soliciting at least some feedback on how it’s being used. I know everything is still in pre-1.0 unstable land but it really upends a lot to have to completely rework something like state transitions because one person got surprised by it.
Re-entering states is definitely a useful thing to be able to do, having this functionality back in some form would be really great to see.