Skip to content

Query for entity with 2 component types doesn't compile #4296

Answered by nicopap
Koettlitz asked this question in Q&A
Discussion options

You must be logged in to vote

You should write Query<(&A, &B)> instead of Query<&A, &B>.

Query<C, F> is a generic type that accepts two type parameters:

  • C: What you want to query for
  • F: The filters, that can limit what will be in the query.

C will be the things you get in the for loop when iterating over the query:

fn my_system(query: Query<&Transform>) {
    for transform in query.iter() {
        //...
    }
}

Here the "query item" (what the query returns) is of type Transform, and you get a Transform when using query.iter() or query.get.

F are "filter", you still get the query items do not change, but the filters limit which items are retrieved:

// now with filter, only retrieve cameras
fn my_system(query: Query<&T…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Koettlitz
Comment options

@alice-i-cecile
Comment options

Answer selected by Koettlitz
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants