CesiumGS / cesium-unity

Bringing the 3D geospatial ecosystem to Unity
https://cesium.com/platform/cesium-for-unity/
Apache License 2.0
358 stars 83 forks source link

Deleting `Cesium3DTileset`, then undoing has irreversible consequences #418

Open j9liu opened 9 months ago

j9liu commented 9 months ago

I accidentally deleted a Cesium3DTileset in one of the sample levels (though it doesn't matter which), and tried to undo it. But this messes up a lot.

Firstly, the console gets spammed with these error messages:

This Mesh Collider is attached to GameObject at path 'CesiumGeoreference/Cesium World Terrain/[url]/Mesh 0 Primitive 0' with Mesh '' in Scene '01_CesiumWorld', but the mesh doesn't have any vertices.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Then, as tiles attempt to reload, many of them will appear purple (indicating a material with errors)... image

... and some of them will appear un-georeferenced. In this screenshot, the purple streaks in the sky are floating tiles. image

I imagine that undoing the deletion is pretty disastrous for the state management of Cesium3DTileset, but I believe it's because the delete operation is recording the deletion of the child game objects -- even those marked HideAndDontSave. So when I undo the operation, it adds back all of those game objects. This prevents the tileset from properly cleaning up when it is disabled and reenabled.

I don't know if this can be prevented, but hopefully there's a way to intercept the undo operation and prevent the tiles from being reattached?