-
I'm trying to run a use bevy::{ecs::schedule::ShouldRun, prelude::*};
fn main() {
App::build()
.add_plugins(MinimalPlugins)
.add_state(MyState::S1)
.add_system_set(
SystemSet::on_enter(MyState::S1)
.with_system(exit_state_1.system())
)
.add_system_set(
SystemSet::on_exit(MyState::S1)
.with_run_criteria(check.system())
.with_system(success.system())
)
.run();
}
struct Marker;
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
enum MyState {
S1,
S2,
}
fn exit_state_1(mut commands: Commands, mut state: ResMut<State<MyState>>) {
commands.spawn().insert(Marker);
state.set(MyState::S2).unwrap();
}
fn check(marker: Query<&Marker>) -> ShouldRun {
dbg!(marker.iter().count());
match marker.single() {
Ok(_) => {
println!("running");
ShouldRun::Yes
},
Err(_) => {
println!("not running");
ShouldRun::No
},
}
}
fn success(marker: Query<&Marker>) {
if let Ok(_) = marker.single() {
println!("hurray");
panic!("terminate");
}
} This code loops indefinitely, printing:
If i comment out the line that adds
If i add the following to the App: .add_system_set(
SystemSet::on_enter(MyState::S2)
.with_system(exit_state_2.system())
) which is: fn exit_state_2(mut state: ResMut<State<MyState>>) {
state.set(MyState::S1).unwrap();
} and move the
What does this mean for the usage of RunCriteria? Is it only supposed be used on update? Are there some learning materials with slightly more advanced examples? My real world usage in this case would be to despawn the current room and trigger the spawning of the next one only when the Player exits the room, while if NPCs exit the room, i want to do something else. But I also really like it to conditionally run systems based on certain conditions, just need to wrap my ahead around it and i guess avoid some footgun? Thanks a lot! (PS: i'm on 0.5, didn't try with main) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
ok i dug a bit more into it. I think the crux of the issue is that when building the bevy/crates/bevy_ecs/src/schedule/system_set.rs Lines 68 to 73 in 43d99bb but then when i add my own bevy/crates/bevy_ecs/src/schedule/system_set.rs Lines 99 to 102 in 43d99bb to me looks like a bug..? I think i'll open an issue. |
Beta Was this translation helpful? Give feedback.
ok i dug a bit more into it. I think the crux of the issue is that when building the
SystemSet
,with_run_criteria
is called:bevy/crates/bevy_ecs/src/schedule/system_set.rs
Lines 68 to 73 in 43d99bb
but then when i add my own
with_run_criteria
, it is overwritten here:bevy/crates/bevy_ecs/src/schedule/system_set.rs
Lines 99 to 102 in 43d99bb