You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way to automatically log state transitions including SubStates? I'm trying to debug my game's state and it would be great if there was a way to know exactly when the App State changes.
Edit:
Got this working with a few steps:
fn main() {
App::new()
.init_state::<GameState>()
.add_sub_state::<GeneratingNewWorld>()
.add_sub_state::<LoadingWorld>()
.add_sub_state::<InGame>()
.add_systems(
First,
(s_run_state_transitions, s_state_transition_logger).chain(),
)
//other app functions...
.run();
}
/// Make sure state transitions are run before anything else for accurate timeline of "events" in stdout
fn s_run_state_transitions(world: &mut World) {
let _ = world.try_run_schedule(StateTransition);
}
fn s_state_transition_logger(
mut game_state_transition: EventReader<StateTransitionEvent<GameState>>,
// SubState
mut generating_new_game_transition: EventReader<StateTransitionEvent<GeneratingNewWorld>>,
// SubState
mut loading_world_transition: EventReader<StateTransitionEvent<LoadingWorld>>,
// SubState
mut in_game_transition: EventReader<StateTransitionEvent<InGame>>,
) {
for event in game_state_transition.read() {
if let Some(state) = event.entered {
println!("ENTERED STATE: {}", state);
}
}
for event in generating_new_game_transition.read() {
if let Some(state) = event.entered {
println!("ENTERED STATE: {}", state);
}
}
for event in loading_world_transition.read() {
if let Some(state) = event.entered {
println!("ENTERED STATE: {}", state);
}
}
for event in in_game_transition.read() {
if let Some(state) = event.entered {
println!("ENTERED STATE: {}", state);
}
}
}
I'm wondering if this is worth opening an issue? Seems a bit too involved for something as simple/common as printing state transitions.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Is there any way to automatically log state transitions including SubStates? I'm trying to debug my game's state and it would be great if there was a way to know exactly when the App State changes.
Edit:
Got this working with a few steps:
I'm wondering if this is worth opening an issue? Seems a bit too involved for something as simple/common as printing state transitions.
Beta Was this translation helpful? Give feedback.
All reactions