Fix: DespawnOnEnter/OnExit/When can trigger for same state transitions#23390
Conversation
|
It looks like your PR is a breaking change, but you didn't provide a migration guide. Please review the instructions for writing migration guides, then expand or revise the content in the migration guides directory to reflect your changes. |
|
Simple migration guide please: this change in behavior might be surprising. |
|
@idlercloud @tacuna @chescock, could I get a second review from one of you? :) |
|
@alice-i-cecile done! All good. |
chescock
left a comment
There was a problem hiding this comment.
Yup, this seems like the right fix!
Looking at the whole thing in context, though, are the semantics of the StateTransitionEvent message that clients should ignore it if entered == exited && !allow_same_state_transitions? If that's the case, should we instead ... not even create the message in those cases? And then we could remove the allow_same_state_transitions field from it? It seems like that would have the same effect, but we'd only have to remember to check the flag in one place.
(But that would definitely be a separate PR, of course!)
bevyengine#23390) # Objective - Fixes bevyengine#23071 - Also allow state scoped messages to clear on same state transitions if desired. ## Solution - Add a `&& !transition.allow_same_state_transitions` check whenever the `entered` state and `exited` state are compared. The `allow_same_state_transitions` property is available from `StateTransitionEvent`. This extra comparison is already being used for `OnEnter` and `OnExit`. ## Testing - Added a unit test to see that DespawnOnExit runs during same state transitions if desired, since the logic is basically the same for all three Despawn* Components. - Ran the `state_scoped` example and everything looks ok
Objective
Solution
&& !transition.allow_same_state_transitionscheck whenever theenteredstate andexitedstate are compared. Theallow_same_state_transitionsproperty is available fromStateTransitionEvent. This extra comparison is already being used forOnEnterandOnExit.Testing
state_scopedexample and everything looks ok