Missing reference exception on a persistent object

I’ve just implemented the portal’s ability to save, and for some reason some of the persistent objects are throwing missing reference exceptions. The fader and portal scripts were working fine initially, so something I’ve done recently has caused an issue. I fixed some of the issues but one is particularly stubborn. That being when I transition between scenes specifically starting in the Sandbox scene (starting in sandbox 2 avoids this issue) and then transition back, I get an error saying the canvas group has been destroyed despite it being on a persistent object. This also causes the fade in to not work properly, but it’s specifically when I start in Sandbox and only when I’m transitioning from Sandbox 2 to Sandbox. My best guess based on that is that something unique to Sandbox like the enemies are causing an issue, but I’m unsure how to fix it.

Edit: Just now noticed I had a persistent objects in the Sandbox 2 scene, that was the culprit.

That’s exactly what I was going to suggest. The persistent objects should only be put in a scene with the spawner.
Unfortunately, the way that Unity manages DontDestroyOnLoad objects is that it moves them from the current scen into a special scene called DontDestroyOnLoad. This scene is always the last place searched in a FindObjectsOfType call, meaning if there is a persistent object in the regular scene already, it will always be found first, and create a null reference mid portal.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms