Shouldn't Identity state transition trigger OnExit/OnEnter ?
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
I don't know about other bevy users but personally my state switching logic always looks something like this:
> if I'm in state A and *condition is met* => transition to state B
There are however many cases where we want state A to lead to state A (refreshing UI, going to the next level when we're already in a level, etc…), so in these cases I naturally try to write:
> if I'm in state A and *condition is met* => transition to state A
wishing to trigger OnExit(state A) and OnEnter(state A). But it doesn't work, as we know. Instead, we have to go through hoops and write quite a bit more code to fulfill this simple need.
Now if there are any **technical** reasons for which it is not desirable to make identity state transition trigger OnExit/OnEnter, I would understand.
If however, if this wasn't implemented for **UX reasons**, then I want to argue this decision, because:
1. this behavior is **desirable** in many legit use cases
1. I always know which state I'm in when I execute a transition, it's part of the natural state machine design;
so there is no way I would "accidentally" transition from state A to state A and be surprised that OnExit/OnEnter triggers, it's **not a footgun**
1. if for some reason I'm blindly transitioning to state A without checking the state I'm in and also didn't want OnExit/OnEnter, the simple solution would be to just… well check the current state ? Problem solved.
So I'm raising this issue to bring up these points because I think it's a common need (from what I could gather on discord anyway) and if it's intentional I think it's interesting to list here the arguments for and against for future google searches :)
Contributor guide
Assessment
This issue has not been assessed yet.