mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Add error message if states schedule missing (usually because StatesPlugin hasn't been added) (#14160)
# Objective - Helps improve https://github.com/bevyengine/bevy/issues/14151 ## Solution - At least return an error message from the `Option::unwrap()` call when we try to access the `StateTransition` schedule --------- Co-authored-by: Martín Maita <47983254+mnmaita@users.noreply.github.com>
This commit is contained in:
parent
99c9218b56
commit
17a77445e2
1 changed files with 6 additions and 2 deletions
|
@ -73,7 +73,9 @@ impl AppExtStates for SubApp {
|
|||
self.init_resource::<State<S>>()
|
||||
.init_resource::<NextState<S>>()
|
||||
.add_event::<StateTransitionEvent<S>>();
|
||||
let schedule = self.get_schedule_mut(StateTransition).unwrap();
|
||||
let schedule = self.get_schedule_mut(StateTransition).expect(
|
||||
"The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling init_state?"
|
||||
);
|
||||
S::register_state(schedule);
|
||||
let state = self.world().resource::<State<S>>().get().clone();
|
||||
self.world_mut().send_event(StateTransitionEvent {
|
||||
|
@ -94,7 +96,9 @@ impl AppExtStates for SubApp {
|
|||
self.insert_resource::<State<S>>(State::new(state.clone()))
|
||||
.init_resource::<NextState<S>>()
|
||||
.add_event::<StateTransitionEvent<S>>();
|
||||
let schedule = self.get_schedule_mut(StateTransition).unwrap();
|
||||
let schedule = self.get_schedule_mut(StateTransition).expect(
|
||||
"The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling init_state?"
|
||||
);
|
||||
S::register_state(schedule);
|
||||
self.world_mut().send_event(StateTransitionEvent {
|
||||
exited: None,
|
||||
|
|
Loading…
Reference in a new issue