some gameobjects don't destroy between scenes using Application.LoadLevel

I’m using 5.2.5 and using Application.LoadLevel to change my scenes.

I don’t understand why a gameobject having some script and GUIText components stays into the next scene. That script has 1880 lines so I won’t paste it here. I don’t use dontDestroyOnLoad inside it and I don’t have static variable.

You should probably start by pouring a circle of salt around your computer. :slight_smile:

Are you doing an additive load or something? I don’t even know if that was a thing back in 5.2.

eheh. I can’t update because one plugin breaks in newer versions.

I forgot one script component on that game object uses some public static variable. That might be the problem?

I haven’t seen a public static variable cause that problem but, again, I haven’t used 5.2.

It’s a long class with, it sounds like, coupling to other parts of the system. What is your confidence level that DontDestroyOnLoad really is not involved?

yeah, I’ve found one (on a script I didn’t write myself). But it’s not that new gameobject “spout” that stays, it’s the gameobject on which the script component is attached. Here is the part:

        public static Spout instance {
            get {
                if(_instance == null){
                    _instance = GameObject.FindObjectOfType<Spout>();
                    if(_instance == null) {
                        GameObject _go = new GameObject("Spout");           
                        _instance = _go.AddComponent<Spout>();
                    }
                    DontDestroyOnLoad(_instance.gameObject);
                }
                return _instance;
            }
            private set{_instance = value;}
        }

Ok, found a workaround. I leave the problematic script component alone on a gameobject that stays through the scene changes and it’s good for me.