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

Fix console errors when entering play mode #342

Closed kring closed 1 year ago

kring commented 1 year ago

Fixes #339

This fixes a couple of errors that are logged to the console when entering Play mode. Specifically this one:

ArgumentNullException: Value cannot be null.
Parameter name: e
UnityEngine.UIElements.UQueryExtensions.Q (UnityEngine.UIElements.VisualElement e, System.String name, System.String className) (at <7f21349c9161407ba80a85ddaed7fabb>:0)
CesiumForUnity.CesiumCreditSystemUI.OnEnable () (at Packages/com.cesium.unity/Runtime/CesiumCreditSystemUI.cs:54)

And this one:

MissingReferenceException: The object of type 'CesiumCreditSystem' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
CesiumForUnity.CesiumCreditSystem.OnSceneUnloaded (UnityEngine.SceneManagement.Scene scene) (at Packages/com.cesium.unity/Runtime/CesiumCreditSystem.cs:333)
UnityEngine.SceneManagement.SceneManager.Internal_SceneUnloaded (UnityEngine.SceneManagement.Scene scene) (at <7b2a272e51214e2f91bbc4fb4f28eff8>:0)

Also fixes a more serious problem (#339) that occurs when Project Settings -> Editor -> Enter Play Mode Settings -> Reload Domain is disabled and prevents tilesets with raster overlays from working at all.

All of these problems are caused by Unity destroying some game objects while we hold references to them, and Cesium for Unity not checking to see if they're still valid before using them.