Skip to content

Add an Entities::iter() method to iterate over all entities when you only have &World #6228

@alice-i-cecile

Description

@alice-i-cecile

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

The ordinary approach for getting the list of entities (query for Query<Entity>) doesn't work in contexts where you only have read-only access to the World.

What solution would you like?

Add an Entities::iter() or World::iter_entities() method.

What alternative(s) have you considered?

The following snippet works

        for archetype in world.archetypes().iter() {
            builder.extract_entities(archetype.entities().iter().copied());

Borrowed from @mockersf in https://github.com/bevyengine/bevy/pull/6227/files#diff-717fbf581c75ed1fc65c9755af2bf8a2ddc97c02e89f4044f86efa70a2ea4260L45

Additional context

It's not entirely clear if Entities::iter() can be implemented directly without digging in; I'm not sure if we have all of the information needed there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions