Description
What problem does this solve or what need does it fill?
The current schedule-based approach to state transitions is messy.
It allows for system ordering ambiguities (#13947), and forces users to reason about a once-per-frame StateTransition
schedule (which other crates may add more copies of).
State transitions hold important global invariants: we should use our new tools to make it easier (and more consistent) to reason about them.
What solution would you like?
- Remove the
StateTransition
schedule. - Make
State<T>
immutable (blocked on Store resources as components on singleton entities #17485). - Remove
NextState
, and make users change states via commands. - Use hooks to call the
OnEnter
/OnExit
/OnTransition
schedules when the state changes. - Remove
.init_state
in favor of simply calling.init_resource
on states. (Use a deprecation notice to make this easier).
What alternative(s) have you considered?
#18562 discusses the possibility of adding another schedule before the initial state transition to allow for startup systems to run before states are entered.
I feel strongly that we shouldn't do this: it should be impossible to be in a state without its on-enter systems to be called (and similarly for on-exit). Instead, we should enforce this invariant as strongly as possible, and ensure that users have the tools needed to delay entering into states until any requisite setup is complete.
Additional context
Note that this conflicts with the desire to run something before states are entered stated in #18562. However, users could simply initialize their starting states in a system during Startup
, rather than calling .init_state
.