-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore overwrite capabilities of insert_state
#13848
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ use bevy_ecs::{ | |
schedule::{IntoSystemConfigs, ScheduleLabel}, | ||
world::FromWorld, | ||
}; | ||
use bevy_utils::tracing::warn; | ||
|
||
use crate::state::{ | ||
setup_state_transitions_in_world, ComputedStates, FreelyMutableState, NextState, State, | ||
|
@@ -70,6 +71,9 @@ impl AppExtStates for SubApp { | |
exited: None, | ||
entered: Some(state), | ||
}); | ||
} else { | ||
let name = std::any::type_name::<S>(); | ||
warn!("State {} is already initialized.", name); | ||
} | ||
|
||
self | ||
|
@@ -87,6 +91,16 @@ impl AppExtStates for SubApp { | |
exited: None, | ||
entered: Some(state), | ||
}); | ||
} else { | ||
// Overwrite previous state and setup event | ||
MiniaczQ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.insert_resource::<State<S>>(State::new(state.clone())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting that there's some duplication between the two branches of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a lot of overlap between all the state methods, we can do a cleanup PR later trying to factorize out the common parts |
||
self.world_mut() | ||
.resource_mut::<Events<StateTransitionEvent<S>>>() | ||
.clear(); | ||
self.world_mut().send_event(StateTransitionEvent { | ||
exited: None, | ||
entered: Some(state), | ||
}); | ||
} | ||
|
||
self | ||
|
@@ -109,6 +123,9 @@ impl AppExtStates for SubApp { | |
exited: None, | ||
entered: state, | ||
}); | ||
} else { | ||
let name = std::any::type_name::<S>(); | ||
warn!("Computed state {} is already initialized.", name); | ||
} | ||
|
||
self | ||
|
@@ -132,6 +149,9 @@ impl AppExtStates for SubApp { | |
exited: None, | ||
entered: state, | ||
}); | ||
} else { | ||
let name = std::any::type_name::<S>(); | ||
warn!("Sub state {} is already initialized.", name); | ||
} | ||
|
||
self | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this is reasonable, although
.init_resource
doesn't warn for this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should 😅