Is there a way to iterate through Query results in the same way as a Vec, or to get a Vec of entities? #14685
-
Following on from issue #14679 about poor performance of Specifically I used |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Collect the entities into a |
Beta Was this translation helpful? Give feedback.
-
Would #14690 be helpful to you? In particular it would allow you to rewrite your system like this: fn handle_verlet_collisions(
mut query: Query<(&mut Transform, &VerletProperties)>,
) {
let mut iter = query.iter();
while let Some((mut tr1, pr1)) = iter.next() {
for (mut tr2, pr2) in iter.reborrow() {
let mut norm = tr2.translation - tr1.translation;
let dist = norm.length();
if dist < pr1.radius + pr2.radius {
let overlap = (pr1.radius + pr2.radius) - dist;
norm = norm.normalize();
if !pr1.pinned {
tr1.translation.x -= norm.x * overlap * 0.5f32;
tr1.translation.y -= norm.y * overlap * 0.5f32;
}
if !pr2.pinned {
tr2.translation.x += norm.x * overlap * 0.5f32;
tr2.translation.y += norm.y * overlap * 0.5f32;
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Collect the entities into a
Vec
usingquery.iter_mut().collect::<Vec<_>>()
.