-
Bevy version0.7 What you did
What went wrongExpected "update" system to process both added and changed components in one frame as that is what happens if I run "change_and_swap" without FixedTimestep. Expected logs:
Got "update" system processing added component and changed one in different frames:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Your issue appears to be misunderstanding of how command application works. The 0.7 docs don't explain it very thoroughly, although some upcoming docs changes are more clear. What's happening in both of your examples, is that 'first'
which you have failed to include here. That is, a tick where only one 'update' occurs. On the tick after diff --git a/src/main.rs b/src/main.rs
index ee557f6..f03c934 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,23 +1,23 @@
use bevy::prelude::*;
-#[derive(Component)]
+#[derive(Component, Debug)]
struct Unique;
-#[derive(Component)]
+#[derive(Component, Debug)]
struct Comp(i32);
fn change_and_spawn(mut commands: Commands, mut query: Query<(&Unique, &mut Comp)>) {
let (_, mut comp) = query.single_mut();
comp.0 += 1;
- commands.spawn().insert(Comp(0));
+ commands.spawn().insert(Comp(comp.0));
}
-fn update(query: Query<&Comp, Changed<Comp>>) {
+fn update(query: Query<(&Comp, Option<&Unique>), Changed<Comp>>) {
let mut print = false;
- for _ in query.iter() {
+ for comp in query.iter() {
print = true;
- println!("update");
+ println!("update {comp:?}");
}
if print {
println!("---------"); |
Beta Was this translation helpful? Give feedback.
Your issue appears to be misunderstanding of how command application works. The 0.7 docs don't explain it very thoroughly, although some upcoming docs changes are more clear.
What's happening in both of your examples, is that 'first'
update
detects the mutation from the same tick.At the very start of your expected output, there should be an instance of:
which you have failed to include here. That is, a tick where only one 'update' occurs.
On the tick after
change_and_spawn
runs,update
then detects theChanged<Comp>
because it was added. In your case where you run the system unconditionally, this happens to coincide with a new run ofchange_and_spawn
, which it als…