Skip to content
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

Only trigger state transitons if next_state != old_state #8359

Merged
merged 1 commit into from
Apr 12, 2023

Conversation

JoJoJet
Copy link
Member

@JoJoJet JoJoJet commented Apr 12, 2023

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.

@JoJoJet JoJoJet added A-ECS Entities, components, systems, and events C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide labels Apr 12, 2023
@alice-i-cecile alice-i-cecile added this to the 0.11 milestone Apr 12, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 12, 2023
@alice-i-cecile
Copy link
Member

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 schedule A.

Updated migration guide suggestion for you. The OnTransition schedules don't exist on 0.10 and your sentence was a fragment.

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 12, 2023
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Apr 12, 2023
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Apr 12, 2023
Merged via the queue into bevyengine:main with commit 7ec8900 Apr 12, 2023
@JoJoJet JoJoJet deleted the state-transitions-fix branch April 12, 2023 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Breaking-Change A breaking change to Bevy's public API that needs to be noted in a migration guide S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

It's surprising that using 'transitioning' to the same state triggers OnEnter
3 participants