Closed junglie85 closed 1 year ago
This should work, but it looks like there's a bug here; thanks for the report! In the mean time, what you probably want to do is use the query (&mut Transform, &Physics, &Drawable, Option<&Input>)
anyway, which will definitely work.
On closer review, this is working as intended. Or
is documented as:
Holds an
L
, or anR
, or both
When an entity satisfies both, you get both. Two &mut Transform
s to the same value would be illegal aliasing. If both clasues of an Or
contain the same &mut T
, you need to ensure that no entity will ever match both. In your case you should use an Option
instead, so that the common references aren't needlessly duplicated.
Ah, you're very right re Or
. I understand now why the error is being raised - my query satisfies both L
and R
so we have two mutable borrows of the same data, which cannot happen.
I originally tried the &Option<Input>
and it didn't work, which is why I reached for Or
. Thanks for your example - I had the borrow in the wrong place!
I want to mutable query for entities which have 2 possible sets of components, like so:
The only difference is that one has an
Input
component.However, when I run this, I get the following error:
Is what I'm trying to do possible and I'm just misunderstanding the API, or is it not possible and I need to do 2 separate queries?