Skip to content

Provide a MapEntities implementation that doesn't require mutable access to the EntityMapper #13114

Open
@cBournhonesque

Description

@cBournhonesque

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

The MapEntities trait (https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/src/entity/map_entities.rs#L46)

pub trait MapEntities {
    fn map_entities<M: EntityMapper>(&mut self, entity_mapper: &mut M);
}

requires a mutable access to the EntityMapper: &mut M

This is because the SceneEntityMapper might generate a new Entity, as seen here: https://github.com/bevyengine/bevy/blob/main/crates/bevy_ecs/src/entity/map_entities.rs#L81

but there are a lot of cases where you might want to just map an entity using an immutable HashMap, in which case you only need a &dyn EntityMapper.

I run into cases where the parallelism of my systems is lowered because I am forced to provide a mutable access to the EntityMapper even though a non-mutable access would be okay. I would appreciate having a way to call map_entities without requiring a mutable access to entity_mapper

What solution would you like?

Maybe the MapEntities trait could have 2 functions map_entities_mut and map_entities? I haven't thought this through.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-NetworkingSending data between clients, servers and machinesC-FeatureA new feature, making something new possibleX-ContentiousThere are nontrivial implications that should be thought through

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions