-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
State change during on_exit causes infinite loop #4271
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior
Description
Bevy version
0.6.1
Operating system & version
Ubuntu 20.04
What you did
I changed the state during a system that runs on exiting a state:
use bevy::prelude::*;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
enum AppState {
A,
B,
}
fn main() {
App::new()
.add_state(AppState::A)
.add_system_set(SystemSet::on_update(AppState::A).with_system(change_state))
.add_system_set(SystemSet::on_exit(AppState::A).with_system(change_state))
.run();
}
fn change_state(mut state: ResMut<State<AppState>>) {
println!("Changing state to B");
state.set(AppState::B).unwrap();
}What you expected to happen
A panic, probably, since either the state transition didn't happen yet (in which case there's a state transition waiting to happen, so set should panic), or the state transition did happen (in which case we're already in state B, so set should panic).
What actually happened
Changing state to B prints forever
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior