Skip to content
Discussion options

You must be logged in to vote

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 the F "filter type." Effectively Query<((Entity, &Component2), With<SerializeMe>), ()>. You're ending up with a second layer of tuple because you're asking for it, and Query is flexible enough to provide it.

What you want is: (edit: also, use query_filtered)

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:

T…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@bbarker
Comment options

@bbarker
Comment options

@alice-i-cecile
Comment options

@rparrett
Comment options

rparrett Nov 9, 2023
Collaborator

Answer selected by bbarker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
A-ECS Entities, components, systems, and events
3 participants