Skip to content

SpatialQuery take ColliderTrees using Res instead of ResMut#956

Merged
Jondolf merged 1 commit into
avianphysics:mainfrom
idanarye:spatial-query-take-collider-trees-as-non-mutable-resource
Mar 17, 2026
Merged

SpatialQuery take ColliderTrees using Res instead of ResMut#956
Jondolf merged 1 commit into
avianphysics:mainfrom
idanarye:spatial-query-take-collider-trees-as-non-mutable-resource

Conversation

@idanarye

Copy link
Copy Markdown
Contributor

Objective

SpatialQuery has this field::

collider_trees: ResMut<'w, ColliderTrees>,

But it only ever uses it for self.collider_trees.iter_trees() - which is a non-&mut method. Having it take the resource as mutable (in Bevy's level - not in Rust's level) needlessly prevents Bevy from parallelizing multiple systems that use SpatialQuery.

Solution

Change it to be Res.

Testing

I ran the cast_ray_predicate example, which uses SpatialQuery, and it seems to run fine.

@Jondolf Jondolf added C-Performance Improvements or questions related to performance A-Spatial-Query Relates to spatial queries, such as ray casting, shape casting, and intersection tests D-Trivial Nice and straightforward! A great choice to get started with Avian labels Mar 17, 2026
@Jondolf Jondolf added this to the 0.6.1 milestone Mar 17, 2026

@Jondolf Jondolf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch, this should definitely be using Res. I'll probably do a 0.6.1 patch release with this fix over the weekend, along with any other fixes we might get by then

@Jondolf Jondolf merged commit 588ed1f into avianphysics:main Mar 17, 2026
6 checks passed
Jondolf pushed a commit that referenced this pull request Mar 23, 2026
…956)

# Objective

`SpatialQuery` has this field::

```rust
collider_trees: ResMut<'w, ColliderTrees>,
```

But it only ever uses it for `self.collider_trees.iter_trees()` - which
is a non-`&mut` method. Having it take the resource as mutable (in
Bevy's level - not in Rust's level) needlessly prevents Bevy from
parallelizing multiple systems that use `SpatialQuery`.

## Solution

Change it to be `Res`.

## Testing

I ran the `cast_ray_predicate` example, which uses `SpatialQuery`, and
it seems to run fine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Spatial-Query Relates to spatial queries, such as ray casting, shape casting, and intersection tests C-Performance Improvements or questions related to performance D-Trivial Nice and straightforward! A great choice to get started with Avian

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants