Skip to content

Allow users to read / write from all components of a given entity using an All WorldQuery types #4278

@alice-i-cecile

Description

@alice-i-cecile

What problem does this solve or what need does it fill?

From time to time, users want to fetch all of the components from a given set of entities.

To do so, they must use the EntityRef or EntityMut API, in an exclusive system.

Fundamentally though, there's no reason this must be done in an exclusive system: this does not impact resource data, and we can limit the archetypes affected when combined with query filters.

What solution would you like?

Create a All type that parallels the API of EntityRef.

This would enable users to write e.g. Query<&All, With<Networked>> in an ordinary system, allowing them to read from any component of the given entity.

This will require some interesting new logic around defining which fetches are needed, but should be relatively straightforward.

Alternatives considered

Initially, I thought we could use EntityRef and EntityMut for this by implementing the WorldQuery trait on them directly. However, EntityMut allows users to add components, which cannot be done in parallel due to the potential impacts on archetypes.

Without the ability to reuse the APIs, IMO it makes more sense just to create a new type and use the standard & vs &mut distinction.

Alternatively alternatively, we could instead use one of the more 🧪 ideas to allow for instant component addition / removals in parallel systems and then just use EntityRef and EntityMut, likely by deferring the archetype updates until the next sync point and storing new component data in a scratch space of sorts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possible

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions