Can't query components made in previous system #10139
-
Hello, i am still relatively new to bevy, but starting to get a grip more and more. After doing a couple tutorials i decided to try out my own game: a simplified civ clone. However, i'm currently running into a seemingly small problem that i might just not be seeing. I want to query the components made inside I have been unable to find any related discussions. Here's the code: App::new()
...
.add_systems(Startup, (
setup::setup,
owners::setup.before(setup::populate_grid),
setup::populate_grid,
))
... // owners.rs
pub fn setup(
mut commands: Commands,
grid: Res<Grid>
) {
let mut rng = rand::thread_rng();
let taken_positions = vec![];
for _ in 0..5 {
let pos = (
rng.gen_range(0..grid.0.width),
rng.gen_range(0..grid.0.height)
);
if taken_positions.contains(&pos) { continue; }
commands.spawn((
Owner { col: random_color(&mut rng), pos }
));
println!("Owner: {:?}", pos);
}
} // setup.rs
pub(crate) fn populate_grid(
mut commands: Commands,
owners: Query<&Owner>
...
) {
println!("ran");
println!("count= {}" , owners.iter().count());
for owner in owners.iter() {
println!("Owner results : {:?}", owner.pos);
}
...
} Output:
Why is count 0? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Commands aren't processed immediately. Instead, they're queued up and applied at the next For now, you'll want to insert a copy of |
Beta Was this translation helpful? Give feedback.
Commands aren't processed immediately. Instead, they're queued up and applied at the next
apply_deferred
synchronization point.For now, you'll want to insert a copy of
apply_deferred
between your systems manually, but #9822 will make your code as written "just work" by doing this for you automatically.