Dont Destroy On New Level?

Hey i have a GameObject called “GM” which stands for Game master.

I want the object and the scripts which is attached to it as components to NOT be destroyed when loading an new level.

I´m using this to prevent it at the momemt.

function Awake ()
{
    DontDestroyOnLoad (transform.gameObject);
}

But then when i get into a new level i keep getting this error -.-

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.

I’m guessing your script is referencing a different gameobject that is destroyed (that doesn’t have DontDestroyOnLoad called on it).

this is reference error.

make sure that the script with the line : DontDestroyOnLoad(this.gameObject);
is attached to the GameObject called “GM”.

Hey guys.

The object is not being destroyed but for some reason the scripts starts to cry in the console

etc. the script attached to my GM Object called “Complete” cries like this:

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.
Complete.Update () (at Assets/Complete.js:16)

we wont be able to properly assist / guide you unless we see the involved script.
with that being said, I think the GameObject with the script ‘Complete’ attached is referencing a GameObject in the previously loaded scene, so you need to check to see if that GameObject is still present.

1 Like

Yeah, like two other people said, you have a script that is referencing a GameObject that no longer exists. That’s as much as anyone can infer from what you have provided.

1 Like