Skip to content

How to query two components simultaneously? #6435

Answered by rparrett
ArikRahman asked this question in Q&A
Discussion options

You must be logged in to vote

Query takes two generic parameters, a query and a filter.

To query for multiple components or to query with multiple filters, you can use a tuple in either position.

fn greet_people(
    query: Query<(&Name, &Age), (With<Person>, With<SillyHat>)>
) {
    for (name, transform) in query.iter() {
        /* ... */
    }
}

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by ArikRahman
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@rparrett
Comment options

rparrett Nov 1, 2022
Collaborator

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