Skip to content

Accessing multiple entities in QueryData/WorldQuery impl #13971

Closed Answered by BigWingBeat
BigWingBeat asked this question in Q&A
Discussion options

You must be logged in to vote

Answer from Giuschi#7708 on Discord:

I don't think this is possible to do with a query. Query assumes that you can get all its elements at once (e.g. with query.iter_mut().collect()). However if in your example you would yield a &mut Foo multiple times (one for each Bar connected to it), which is not sound according to Rust's rules.
You'll have to separately query for &mut Foos and borrow from that query when you want to do something with a Bar. You could possibly wrap this in a custom SystemParam to make it a bit more ergonomic, but fundamentally you'll have to do the query in separate steps.
I don't think relationships will help because you likely won't be able to modify the relationsh…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

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