Provide a MapEntities implementation that doesn't require mutable access to the EntityMapper
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## 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(&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.
Contributor guide
Research direction
Start in crates/bevy_ecs/src/entity/map_entities.rs, especially the MapEntities trait, EntityMapper, and SceneEntityMapper implementations. Compare the existing mutable mapping flow with the requested immutable HashMap-style use case. Done should provide a way to map entities without mutable mapper access while retaining support for mappers that generate new entities.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100