Closed CaioLC closed 2 years ago
Try this:
.add_enter_system(GameState::InGame, setup_game);
UPD: Although… You go from the state of InGame to InGame. I don't think that's a good thing…
UPD2: For debugging, I use:
pub struct DebuggingPlugin;
impl Plugin for DebuggingPlugin {
fn build(&self, app: &mut App) {
app.add_plugin(FrameTimeDiagnosticsPlugin::default())
.add_plugin(LogDiagnosticsPlugin::default())
.add_plugin(WorldInspectorPlugin::default())
.add_system(bevy::input::system::exit_on_esc_system)
.add_system(change_game_state.run_if(n_key_just_pressed))
.add_system(print_current_game_state);
}
}
fn change_game_state(mut commands: Commands, game_state: Res<CurrentState<GameState>>) {
match game_state.0 {
GameState::AssetLoading => {
commands.insert_resource(NextState(GameState::MainMenu));
}
GameState::MainMenu => {
commands.insert_resource(NextState(GameState::Gameplay));
}
GameState::Gameplay => {
commands.insert_resource(NextState(GameState::AssetLoading));
}
}
}
fn n_key_just_pressed(keys: Res<Input<KeyCode>>) -> bool {
keys.just_pressed(KeyCode::N)
}
fn print_current_game_state(game_state: Res<CurrentState<GameState>>) {
if game_state.is_changed() {
println!("Current GameState is {:?}", game_state.0);
}
}
I found that placing .add_loopless_state(X) before I loaded any plugins solved this issue for me.
@arewerage thanks. Removing the reference (&) at &GameState::Ingame fixed it.
Your UPD is also correct. "NextState" from InGame to InGame put me in an endless loop, so removed that as well.
I have a barebones StatePlugin that crashes whenever I try to
add_enter_system()
. I saw another opened issue mentioning that the API may have some issue with the Plugin architecture, so I tried moving theadd_enter_system
tomain
but did not work either.this is the error I get:
Here's a snippet of my main.rs file
and the StatePlugin file:
What am I doing wrong? Thanks!