-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
System are not executed when using State, custom stage and system set. #2312
Comments
You don't need custom stages, you can use Every stage which has system(set)s which use states needs a |
@Ixentus Thanks! By adding those lines, it works as expected. (I would like to make my stage, because gamepad input system uses I also would like to make another state, such as If loading is done, loading system sets will update the state from #[derive(Debug, Clone, Eq, PartialEq, Hash)]
enum MyState {
Loading, // <- Added
InGame, // <- Renamed
}
fn load_system(mut state: ResMut<State<MyState>>) {
// Prepare something (such as texture loading) and wait until done.
// ...
// if loading.is_done() {
state.replace(MyState::InGame).unwrap();
//}
} I added this feature to previous example (full source), and it also works as expected, but roughly. fn main() {
// Added
let loading_system_set = SystemSet::on_update(MyState::Loading)
.with_system(load_system.system());
let before_system_set = SystemSet::on_update(MyState::InGame)
.with_system(print_before_system.system());
let after_system_set = SystemSet::on_update(MyState::InGame)
.with_system(print_after_system.system());
let update_system_set = SystemSet::on_update(MyState::InGame)
.with_system(print_system.system());
App::build()
.add_plugins(DefaultPlugins)
.add_stage_before(
CoreStage::Update,
MyStage::BeforeRound,
SystemStage::parallel(),
)
.add_stage_after(
CoreStage::Update,
MyStage::AfterRound,
SystemStage::parallel(),
)
.add_state_to_stage(MyStage::BeforeRound, MyState::Loading)
.add_state_to_stage(CoreStage::Update, MyState::Loading)
.add_state_to_stage(MyStage::AfterRound, MyState::Loading)
.add_system_set_to_stage(CoreStage::Update, loading_system_set) // <- Added
.add_system_set_to_stage(MyStage::BeforeRound, before_system_set)
.add_system_set_to_stage(CoreStage::Update, update_system_set)
.add_system_set_to_stage(MyStage::AfterRound, after_system_set)
.run();
} It prints:
(Note: There is no First,I can't understand why it works. Why I don't have to call And, how can I make sure |
There is only 1 state (which can be Loading or InGame). So don't replace it in every stage. The docs say that should fail if the new state matches the current state. Now the reason "Update" is ran before "Before Update" is that the Loading system is ran in the Update stage. When it sets the state to InGame, it is still in the update stage. So |
I see, thanks. I read the source and I found State is just a resource, and not owned by each stages: bevy/crates/bevy_app/src/app_builder.rs Lines 260 to 271 in 73ae6af
As written in doc, this style also works (For me, this style makes me relieved, because I don't need to insert the same status for many times.): .insert_resource(State::new(MyState::Loading))
.add_system_set_to_stage(MyStage::BeforeRound, State::<MyState>::get_driver())
.add_system_set_to_stage(CoreStage::Update, State::<MyState>::get_driver())
.add_system_set_to_stage(MyStage::AfterRound, State::<MyState>::get_driver())
I see... So I tried to move Then, it works perfectly!
|
Thank you, @Ixentus and @NathanSWard ! |
Glad we could help. Hopefully the next iteration of States and Stages will be easier to use :) |
Oh, I'm really looking forward it! |
Bevy version
0.5
Operating system & version
Windows 10 + Rust 1.52.1
What you did
I would like to use custom stage and custom system state, and would like to switch them using by
State<T>
.Here is a complete example: __report__bevy_scheduing_sample/main.rs
Here is a main function:
What you expected to happen
I have expected this app prints:
What actually happened
Additional information
I would like to use custom stage (in this example,
MyStage::BeforeRound
andMyStage::AfterRound
) to interact with components spawned inCoreStage::Update
. Any other solution is available to do that? According to #1613, I understood that we have to use custom stages.The text was updated successfully, but these errors were encountered: