Trait bevy_ecs::entity::EntityMapper
source · pub trait EntityMapper {
// Required method
fn map_entity(&mut self, entity: Entity) -> Entity;
}
Expand description
An implementor of this trait knows how to map an Entity
into another Entity
.
Usually this is done by using an EntityHashMap<Entity>
to map source entities
(mapper inputs) to the current world’s entities (mapper outputs).
More generally, this can be used to map Entity
references between any two Worlds
.
§Example
pub struct SimpleEntityMapper {
map: EntityHashMap<Entity>,
}
// Example implementation of EntityMapper where we map an entity to another entity if it exists
// in the underlying `EntityHashMap`, otherwise we just return the original entity.
impl EntityMapper for SimpleEntityMapper {
fn map_entity(&mut self, entity: Entity) -> Entity {
self.map.get(&entity).copied().unwrap_or(entity)
}
}
Required Methods§
sourcefn map_entity(&mut self, entity: Entity) -> Entity
fn map_entity(&mut self, entity: Entity) -> Entity
Map an entity to another entity