-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
It's surprising that using 'transitioning' to the same state triggers OnEnter
#8191
Comments
I'd like to see docs for this, and a set_if_neq method on NextState IMO |
Note that this would need to compare to the value in |
Wouldn't it be enough to just change |
Hmm. Maybe with the addition of the |
What are the use cases for wanting self -> self transitions to trigger things? I'm sure there are some, I just can't think of any. But I think it's reasonable to say "this is weird enough that you have to do something different". |
To me this is the standard "power cycle" pattern, where you reinitialize everything to reset the state :) |
# Objective Fix #8191. Currently, a state transition will be triggered whenever the `NextState` resource has a value, even if that "transition" is to the same state as the previous one. This caused surprising/meaningless behavior, such as the existence of an `OnTransition { from: A, to: A }` schedule. ## Solution State transition schedules now only run if the new state is not equal to the old state. Change detection works the same way, only being triggered when the states compare not equal. --- ## Changelog - State transition schedules are no longer run when transitioning to and from the same state. ## Migration Guide State transitions are now only triggered when the exited and entered state differ. This means that if the world is currently in state `A`, the `OnEnter(A)` schedule (or `OnExit`) will no longer be run if you queue up a state transition to the same state `A`.
Bevy version
0.10
What you did
I was writing a system to transition to a "game over" state when the player's HP hit zero and one to show the UI on entering that state:
What went wrong
Since
NextState
triggersOnEnter
schedules unconditionally, this code constantly generates UI nodes. I assumed that sinceStates: Eq
, bevy would compare the next state to the current state, see that they're the same, and just do nothing (similar toDetectChangesMut::set_if_neq
).The text was updated successfully, but these errors were encountered: