QueryData
tuple or With
?
#19819
-
Hi there, simple newbie question: In the tutorial, fn greet_people(query: Query<&Name, With<Person>>) {
for name in &query {
println!("hello {}!", name.0);
}
} However, I can also write it like this: fn greet_people(query: Query<(&Name, &Person)>) {
for (name, _) in &query {
println!("hello {}!", name.0);
}
} and am curious about the benefit filtering provides compared to direct selecting. I tried searching for answers in https://docs.rs/bevy/latest/bevy/ecs/prelude/struct.Query.html, but couldn't find anything. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
It'd be interesting to profile this! My belief is it speeds you up ever so slightly to use |
Beta Was this translation helpful? Give feedback.
-
The obvious benefit I can think of is that you can run the system at the same time as another system that requests mutable access to |
Beta Was this translation helpful? Give feedback.
The obvious benefit I can think of is that you can run the system at the same time as another system that requests mutable access to
Person
, since it doesn't need access to the data, and a mutable system can't remove it (while executing). There's more than justWith
filter (such asWithout
), so it's good to get used to it, and it's certainly the appropriate way to do things in this case.