bevyengine / bevyengine/bevy

Read-only queries cannot be issued on a read-only &World

Open
#3,774 11 comments 12 reactions 0 assignees View on GitHub
A-ECS C-Usability S-Ready-For-Implementation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Problem

Given a `&World`, I cannot issue a query that only reads from the world.

There are two possible methods on `World` for this: `query`, `query_filtered`, plus `SystemState::new()`. All of them require `&mut World`, as they *could* provide mutating type parameters.

## Proposed Solutions

### Quick-and-dirty

Make read-only variants of all three methods.

### Ergonomic

Add a `system_state` and `read_only_system_state` method to `World`, which generates a `SystemState` and then immediately calls `.get_mut` / `.get` on it.

This allows users to do things like:

```rust
let query = world.read_only_system_state::>>();

for (foo, bar) in query.iter(){

}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.