Function bevy::ecs::prelude::apply_state_transition
pub fn apply_state_transition<S>(
event: EventWriter<'_, StateTransitionEvent<S>>,
commands: Commands<'_, '_>,
current_state: Option<ResMut<'_, State<S>>>,
next_state: Option<ResMut<'_, NextState<S>>>
)where
S: FreelyMutableState,
Expand description
If a new state is queued in NextState<S>
, this system:
- Takes the new state value from
NextState<S>
and updatesState<S>
. - Sends a relevant
StateTransitionEvent
- Runs the [
OnExit(exited_state)
] schedule, if it exists. - Runs the
OnTransition { from: exited_state, to: entered_state }
, if it exists. - Derive any dependent states through the [
ComputeDependantStates::<S>
] schedule, if it exists. - Runs the [
OnEnter(entered_state)
] schedule, if it exists.
If the State<S>
resource does not exist, it does nothing. Removing or adding states
should be done at App creation or at your own risk.
For SubStates
- it only applies the state if the SubState
currently exists. Otherwise, it is wiped.
When a SubState
is re-created, it will use the result of it’s should_exist
method.