Missing Reference Exception

MissingReferenceException: The object of type ‘GameObject’ 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.
Reinterop.ReinteropInitializer.UnityEngine_GameObject_Property_get_transform (System.IntPtr thiz) (at Library/PackageCache/com.cesium.unity@1.0.0/Runtime/generated/Reinterop/Reinterop.RoslynSourceGenerator/ReinteropInitializer.cs:37093)
(wrapper native-to-managed) Reinterop.ReinteropInitializer.UnityEngine_GameObject_Property_get_transform(intptr)
CesiumForUnity.CesiumIonRasterOverlay.RemoveFromTileset (CesiumForUnity.Cesium3DTileset tileset) (at Library/PackageCache/com.cesium.unity@1.0.0/Runtime/generated/Reinterop/Reinterop.RoslynSourceGenerator/CesiumIonRasterOverlay-generated.cs:322)
CesiumForUnity.CesiumRasterOverlay.RemoveFromTileset () (at Library/PackageCache/com.cesium.unity@1.0.0/Runtime/CesiumRasterOverlay.cs:165)
Reinterop.ReinteropInitializer.CesiumForUnity_CesiumRasterOverlay_CallRemoveFromTileset_1B2M2Y8AsgTpgAmY7PhCfg (System.IntPtr thiz) (at Library/PackageCache/com.cesium.unity@1.0.0/Runtime/generated/Reinterop/Reinterop.RoslynSourceGenerator/ReinteropInitializer.cs:33165)

I received an error message when trying to add Cesium to my project. It appears that Cesium works fine for a new project, but when I try to add it to my existing map to update it, I receive the error message shown below.

Since the error is occurring in the “Package” folder instead of the “Asset” folder, I am unable to trace where exactly this error is coming from. I also found a similar bug in version v0.3.0 by checking the bug issue log on Github. It appears that this issue was resolved in version v0.3.1. Do you have any ideas on how to fix this problem?

Thank you very much.

I’m not sure. Is there anything in your existing project that could be destroying Cesium’s game objects? Also check that you’re running the latest version of Cesium for Unity, v1.0.0, by looking in the Unity Package Manager.

I’m sorry for can’t give more specific information, since I’m not a expert in unity. :sweat_smile:
Thanks for your answer, we decided to build our project again from skrect again, the Cesium works fine!~

I ran into this as well. Standing up a new project to use Cesium in never gives any issue. However, when you try to add it to an existing project, the error described here will appear and it breaks everything.

I have a geospatial app I’ve been developing for a while and want to “switch” my current globe out for Cesium. This error prevents that in my project and a couple other existing projects I have tried it on. Getting the package into the project, using the editor GUIs, and flying around the globe in Scene view all work fine. When you hit Play though, it blows up.

Using latest 1.3.1 version of Cesium and 2022.3.3f1 Unity

Can you provide us with a project that we can use to reproduce this problem?

Yes, one of the projects I reproduced this on was from a YouTube tutorial video.


The full project can be acquired in the video description. I can also get my specific copy of that project, but I don’t think there will be a difference. Obviously that project and tutorial aren’t related to Cesium, it was just an older project that I had to test reproducibility.

All, I did was follow the Quick Start guide for Cesium, then at the end when your ready to hit play, the error filled the console.

Interesting that the tutorial you linked uses DOTS. I wonder if that’s the key to the problem. Do other projects where you’ve seen the problem also use DOTS?

In any case, thanks for the links. I’ll try it out soon.

Ok, I can reproduce this. The problem is caused by disabling Domain and/or Scene Reload when entering Play mode.

Go to Edit → Project Settings → Editor. There’s an “Enter Play Mode Settings” section near the bottom. By default, it looks like this:


With the “options” disabled, Unity does the full domain and scene reload when entering Play mode, and this will work just fine.

However, in the project you pointed me to, the settings look like this:


Which tells Unity to skip both domain and scene reload. With this setup, you’ll get the MissingReferenceExceptions when entering play mode. Disable the “Enter Play Mode Options”, or enable “Reload Domain” and “Reload Scene”, and the problem will go away.

I’ve written an issue for us to investigate further why this happens and what we can do about it.

1 Like

Yep, that did it. I think at some point I picked that up from somewhere as a setting to turn on to “get into play mode faster”. I appreciate the assist man :metal:

Thanks for your help tracking it down. We included a fix in the v1.4.0 release this week, so you should be able to turn Reload Domain back off after you upgrade.

1 Like