Missing Object "SavingWrapper" has been destroyed but it shouldnt be

Update: I am still struggling with the issue but after a few days of testing around and rewatching videos, I thought I would update this ask and give it better readability and form.

So I have the PersistentObjects prefab functioning as it only spawns the prefab once and between scenes, it stays, not deleted. When I transition to scene 2, it functions normally, I get the fade script, I get the save and load script. And then I fade into scene 2. When I go back to scene 1, it’ll fade out, save and then error.

Error: MissingReferenceExcpetion: The object of type ‘SavingWrapper’ 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.

When I deleted the saving wrapper segment of the code and had it with just the fader script, it also gave the same error with the exception of it being ‘Fader’ instead. Both the SavingWrapper and the Fader are attached to the PersistentObjects prefab and from what I understand, it functions properly. But I do not understand what is causing it to lose the reference between scenes.

I tried removing the saving function from the portal script and just leaving the load function with the reference to the SavingWrapper after the load scene and that actually worked but I still had the same error for ‘Fader’ meaning there was no fade in.

I am currently in Unity 2020.3.0f1 but when I checked the documentation for the versions, I didn’t see any changes between DontDestroyOnLoad();

I hope this better explains my problem.

My very first thought on this is to check your second scene. You might find that there is a SavingWrapper hiding in the heirarchy somewhere. Fader will always find the first instance of SavingWrapper, but the way Unity structures a scene, DontDestroyOnLoad elements are always AFTER anything found within the scene file, meaning Fader will find a stray SavingWrapper and use it, then after the scene loads, it’s still holding the SavingWrapper reference to a wrapper that no longer exists while the persistent one sits unused.

1 Like

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