-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
What problem does this solve or what need does it fill?
Right now we can write to a world from a scene using
let instance = scene.write_to_world_with(world, app_type_registry) .unwrap();
Where the returned instance is a mapping from entities in the scene world to entities to newly created entities in the world we pass in.
However, in some cases we want to overwrite entities in the world (instead of allocating new ones). Say I have many snapshots of my world in-memory that I've saved using Scene::clone_with
. When I apply them to the world I don't want to allocate new entities each time - instead I want to be passing in the scene instance entity map I got back from my write_to_world_with
call and overwriting the entities that way.
What solution would you like?
Sample API
impl Scene {
...
/// Overwrites entities specified in the scene that have an existing mapping to an entity in world
pub fn overwrite(&self, world: &mut World, instance_info: InstanceInfo) {
let entity_map = instance_info.0;
...
}
...
}
This can be used as so
#[derive(Component)]
pub struct A(u32);
let mut world = World::default();
let scene = Scene::new(world);
let mut entity_mut = scene.world.spawn(A(0));
let snapshot = scene.clone_with(app_type_registry).unwrap();
entity_mut.insert(A(1));
let instance = scene.write_to_world_with(main_world, app_type_registry) .unwrap();
// load an older snapshot but reuse all the same entities
snapshot.overwrite(world, instance);
Additional considerations
We could also consider removing entities that are in the InstanceInfo
but not in the scene from the world, but a straightforward overwrite
would work for my use case.