-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
enable same state transitions #19363
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
base: main
Are you sure you want to change the base?
Conversation
How does this approach interact with computed and sub states? |
Labeling as contentious given that all previous work in this regard was contested |
We might want a working group for My take on this particular feature though is that it's so basic and crucial that it's worth introducing technical debt to get it in even without a redesign (obviously since I've tried to do just that in 4 separate PRs). Just need to document how it interacts with computed and sub states. |
I think it doesn't, it's only enabled when actually calling the method on This is scoped as small as I think is viable, the only extra thing in this PR is making sure that if |
But what So whether this is just a naming thing, or a flaw in the design, I'm not sure, but I also wondered whether you'd do this at the place you actually change the state (as in this PR), or if you do it in the definition of your states (if it's technically possible). |
What do you think of
I think it's better to do it like in this pr. If we want to go for a breaking change, I would probably make this PR the default, and change the current |
What's your thinking? Is it because you specifically want per-call site control over this? The reason I mentioned it is that when coming up with a name and design for the per-call site version (this PR), it seems hard to come up with a concise and expressive design whereas when it's defined at the type level, it becomes easier to express. For example, maybe it looks something like this: #[derive(States)]
enum GameState {
#[default]
MainMenu,
SettingsMenu,
InGame,
}
// Default behavior: schedules skipped for identical states.
impl StateTransitionBehavior for GameState {
fn always_run_entry_exit_transitions() -> bool { false }
}
#[derive(States)]
enum ResettingState {
#[default]
Idle,
Active,
}
// Always run transitions, even for identical states.
impl StateTransitionBehavior for ResettingState {
fn always_run_entry_exit_transitions() -> bool { true }
}
fn set_game_state(mut next_game_state: ResMut<NextState<GameState>>) {
// Standard behavior: schedules skipped if state is unchanged.
next_game_state.set(GameState::InGame);
}
fn set_resetting_state(mut next_state: ResMut<NextState<ResettingState>>) {
// Schedules always run, even if state is unchanged.
next_state.set(ResettingState::Active);
} That aside, if we're trying to do this in the next_game_state.set(GameState::InGame).with_entry_exit_transitions().apply() But it raises questions of compatibility which we'd have to decide on. If I had to pick something on the next_game_state.set_with_entry_exit(GameState::InGame); // or:
next_game_state.set_with_entry_exit_transitions(GameState::InGame); (noting that I picked Or, if you want to change next_game_state.set_without_entry_exit(GameState::InGame); // or:
next_game_state.set_without_entry_exit_transitions(GameState::InGame); If you wanted a breaking change and you want per-call site control, I think a builder pattern could work here and would be the most expressive. |
Objective
Solution
set_forced
method onNextState
that will triggerOnEnter
andOnExit
set_forced
has been usedset
is called afterset_forced
with the same state