Bevy version and features
0.18.1
What you did
I combined system conditions with and() so on_countdown_completed would run when Countdown reached zero. I added not(resource_added::<Countdown>) because I didn't want it to run immediately after the resource was added, but that didn’t work.
use bevy::prelude::*;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, Resource)]
struct Countdown(usize);
fn on_countdown_completed(countdown: Res<Countdown>) {
dbg!(countdown.is_added(), countdown.is_changed(), countdown.0);
println!("countdown completed")
}
fn main() {
App::new()
.add_plugins(MinimalPlugins)
.init_resource::<Countdown>()
.add_systems(
Update,
on_countdown_completed.run_if(
// This system should not run if Countdown was just added.
not(resource_added::<Countdown>)
// This system should run if Countdown was decremented to zero.
.and(resource_changed::<Countdown>)
.and(resource_equals(Countdown(0))),
),
)
.run();
}
What went wrong
on_countdown_completed runs when countdown.is_added() is true.
[src/main.rs:7:5] countdown.is_added() = true
[src/main.rs:7:5] countdown.is_changed() = true
[src/main.rs:7:5] countdown.0 = 0
countdown completed
Replacing not(resource_added::<Countdown>) with resource_added::<Countdown> produced the same output.
What's going on?
Bevy version and features
0.18.1
What you did
I combined system conditions with
and()soon_countdown_completedwould run whenCountdownreached zero. I addednot(resource_added::<Countdown>)because I didn't want it to run immediately after the resource was added, but that didn’t work.What went wrong
on_countdown_completedruns whencountdown.is_added()istrue.Replacing
not(resource_added::<Countdown>)withresource_added::<Countdown>produced the same output.What's going on?