I am unsure whether I am confusing what the Bevy's Change Detection systems do , or if I am just doing it wrong. But, in attempts to detect changes, I am only notified when the component is spawned.
Below, I spawn
a tuple of Group,Size(2)
. Then, sizequery
is run each frame until the size is 5. In this time, groupsize
only runs once, at size 2. Why is this?
use bevy:: {
prelude::*,
};
fn main () {
App::build()
.add_resource(WindowDescriptor {
..Default::default()
})
.add_default_plugins()
.add_startup_system(setup.system())
.add_plugin(TestPlugin)
.run();
}
struct Group;
struct Size(u32);
fn setup(mut commands: Commands) {
commands.spawn((Group,Size(2)));
}
fn groupsize(mut query: Query<Changed<Size>>) {
for s in &mut query.iter() {
println!("GS-{}",s.0);
}
}
fn sizequery(mut query: Query<&mut Size>) {
for mut s in &mut query.iter() {
if s.0 < 5 {
s.0 = s.0+1;
println!("add{}",s.0);
}
}
}
pub struct TestPlugin;
impl Plugin for TestPlugin {
fn build(&self, app: &mut AppBuilder) {
app.add_system(groupsize.system());
app.add_system(sizequery.system());
}
}
Cargo.toml:
[package]
name = "bevy_test"
version = "0.1.0"
edition = "2018"
[dependencies]
bevy = "0.1.3"