After updating to 0.7.1 we occasionally hit a KeyNotFoundException, after these steps:
Unload a scene
Resources.UnloadUnusedAssets();
Load another scene
It looks like it might be a reference that is freed before the RealityKit side is fully done with it. The same setup worked fine in 0.6.3.
This is an example of the error in XCode:
KeyNotFoundException: The given key 'a2bdda7f-646c-4bb4-93b6-bf4af24aeaca' was not present in the dictionary.
at System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) [0x00000] in <00000000000000000000000000000000>:0
at Unity.PolySpatial.Internals.LocalAssetManager.UnregisterUnityReference (Unity.PolySpatial.Internals.PolySpatialAssetID assetID) [0x00000] in <00000000000000000000000000000000>:0
at Unity.PolySpatial.Internals.LocalAssetManager.ProcessChanges () [0x00000] in <00000000000000000000000000000000>:0
at Unity.PolySpatial.Internals.PolySpatialUnitySimulation.Update () [0x00000] in <00000000000000000000000000000000>:0
at Unity.PolySpatial.Internals.PolySpatialCore.PolySpatialAfterLateUpdate () [0x00000] in <00000000000000000000000000000000>:0
Hi,
Something you could potentially try is to wrap the Resources.UnloadUnusedAssets()
and scene load call in a coroutine. After the call to Resources.UnloadUnusedAssets()
, yield for a frame to allow for cleanup and unregistration of resources.
If this issue persists, can you submit a bug report and a repro project? I tried something similar - ran
Resources.UnloadUnusedAssets();
SceneManager.LoadScene("NewScene");
but I wasn’t seeing that particular error message; I want to make sure I’m addressing the right issue here. Thank you!
We have made a workaround that destroys instanced materials and meshes from the scene that is being unloaded. That was primarily what was being left behind in our case. It seems to work without issues.
Unfortunately we don’t have time for a lot of debugging, so this will be the “solution” we use for now.
The soft-crash happened maybe once every 10 levels on simulator, and once every 60 levels on device. It suggests to me that it was related to an asset being unloaded before RealityKit was completely done with cleaning up. As the simulator is much slower than the device, it would make sense it crashes more in that scenario.
1 Like