Skip to content

Mutate two components of a query at the same time #8075

Answered by nicopap
100-TomatoJuice asked this question in Q&A
Discussion options

You must be logged in to vote

You need to store your position differently. I suggest one of the following:

  • use a different component for position. Here you are struggling because position is a field of Element, while really it should be its own component. This way you can figure out neighbours without requiring access to Element, which prevents mutating it. I suggest a Query<(Entity, &Position), With<MovableSolid>>
  • Ideally, to avoid having to iterate over all entities to find neighbours, you should store position -> Entity map or grid of entities in a Res.

Then, in your system, get the pair (Entity, Entity) for each falling element and potential target, and use the Query::get_many_mut method. Then you can do:

let Ok([

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@100-TomatoJuice
Comment options

Answer selected by 100-TomatoJuice
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants