#Reloading a spawned DynamicScene does not reuse the SceneInstance entity. Bug?

4 messages · Page 1 of 1 (latest)

heady lance
#

I have a very basic dynamic scene that has been serialized to a .scn.ron file. When I spawn this dynamic scene using a DynamicSceneBundle, an entity is created with the handle and a SceneInstance component. The contents of that scene is spawned as a child of that entity, as expected.

The unexpected part is that upon editing the entity id in the .scn.ron file and saving, the scene is reloaded, but it does not reuse the initial entity that has the SceneInstance component. Instead, the contents of my scene are dropped right in the root. Not only that, but it also does not clean up the now out-of-date scene that was initially spawned.

My expectation would be that the children of entity with the SceneInstance component would be despawned, then my scene contents will be spawned as children, taking place of the old entities.

One thing to note is that this only happens if scene is edited by changing the entity id. This leads me to believe that the intended design for scene reloading in cases where there is no SceneInstance and Handle components to use as a reference point, the spawner just looks for an entity with the same id and spawns a new one if it does not exist. However, when there is a SceneInstance and Handle combo, I would expect the spawner to find the entity with the matching SceneInstance + Handle, wipe out the children, then spawn in the scene contents as children.

Perhaps I am misunderstanding how to spawn or manage reloading. The video shows this behavior. When I press Q, the scene is loaded using a DynamicSceneBundle. When I press P, the scene is saved, causing the asset to then be reloaded. As I said earlier though, pressing P is not required, you only need to edit the entity id on line 4 of my_scene.scn.ron. Bevy has the default and file_watcher features enabled.

viral oxide
#

If you modify entity ids, you need to update the EntityMapper with what changed

heady lance
#

Interesting. I assumed EntityMapper would be updated automatically since the id change happens at time of spawning. I'll give that a shot

heady lance
#

SceneSpawner doesn't actually use EntityMapper it seems. When a scene is spawned, I can get the InstanceId. SceneSpawner has a map from InstanceId to InstanceInfo, and InstanceInfo has a mapping between entities, but it is just a HashMap<Entity, Entity>. There also seems to be no way to access that entity mapping or the InstanceInfo, let alone mutably.