Trait bevy::ecs::entity::MapEntities
pub trait MapEntities {
// Required method
fn map_entities(&mut self, entity_mapper: &mut EntityMapper<'_>);
}
Expand description
Operation to map all contained Entity
fields in a type to new values.
As entity IDs are valid only for the World
they’re sourced from, using Entity
as references in components copied from another world will be invalid. This trait
allows defining custom mappings for these references via EntityHashMap<Entity, Entity>
Implementing this trait correctly is required for properly loading components with entity references from scenes.
Example
use bevy_ecs::prelude::*;
use bevy_ecs::entity::{EntityMapper, MapEntities};
#[derive(Component)]
struct Spring {
a: Entity,
b: Entity,
}
impl MapEntities for Spring {
fn map_entities(&mut self, entity_mapper: &mut EntityMapper) {
self.a = entity_mapper.get_or_reserve(self.a);
self.b = entity_mapper.get_or_reserve(self.b);
}
}