-
world
.query::<(Entity, &Component1)>()
.iter(&world)
.for_each(|(ent, _)| {
println!("C1 entitiy: {:?}", ent);
});
world
.query::<((Entity, &Component2), With<SerializeMe>)>()
.iter(&world)
.for_each(|(ent, _)| {
println!("C2 entitiy: {:?}", ent);
}); This gives output like:
I'm just curious if I'm doing these queries in the ideal fashion. They work, but in the second case, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
In the case of the second example, you're using a big ol' tuple for the What you want is: (edit: also, use world
.query_filtered::<(Entity, &Component2), With<SerializeMe>>()
.iter(&world)
.for_each(|(ent, _)| {
println!("C2 entitiy: {:?}", ent);
}); Note: Rust is also flexible enough to destructure this nested tuple: .for_each(|((ent, _), _)| { Note 2: This confusing situation should be resolved by #9918 which would not allow filters in the fetch type. |
Beta Was this translation helpful? Give feedback.
Query
has two generic types:Query<Q, F>
.In the case of the second example, you're using a big ol' tuple for the
Q
"query fetch" type, and the default value()
for theF
"filter type." EffectivelyQuery<((Entity, &Component2), With<SerializeMe>), ()>
. You're ending up with a second layer of tuple because you're asking for it, andQuery
is flexible enough to provide it.What you want is: (edit: also, use
query_filtered
)Note:
Rust is also flexible enough to destructure this nested tuple:
Note 2:
T…