Skip to content

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

Open
@alice-i-cecile

Description

@alice-i-cecile

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:

let query = world.read_only_system_state::<Query<(&Foo, &Bar), With<Bat>>>();

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

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions