Fader stops working while trying to load next scene

On the Avoiding The Singleton Pattern video, after adding everything and watching the video over and over again to make sure I didn’t miss anything, I keep getting this error message:

MissingReferenceException: The object of type ‘CanvasGroup’ has been destroyed but you are still trying to access it.

I don’t understand why it’s doing it as the object it points me to is still existent in the scene and hasn’t been destroyed yet as the fader hasn’t faded back in yet. Can anyone help me?

This is most likely because you still have a fader within the scene. Your scene file should not have a Fader, SavingWrapper, or SavingSystem in it, or GetComponent<Fader>() will get the fader in the Scene file instead of the one instantiated in the PersistentObjectsPrefab.

I have figured it out. I watched the video one more time and every thing that was done I looked at my code and make sure it was exactly how he did it. After a little bit of going through, I found my mistake. In the DontDestroyOnLoad() method, I accidentally put in the persistentObjectPrefab and not the persistenObject GameObject we had made the line prior. After changing that, and making saving everything worked as it was supposed to. I’m assuming my putting the prefab was doing what you were saying. Thank you very much for your help!!

Ah, yes, in this case, the Fader would be in the PersistentObjects GameObjects, but it would then be destroyed on the scene change. Good job working that out!

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

Privacy & Terms