DontDestroyOnLoad(transform.gameObject) deletes after 2 scene loaded.

I have an object to hold the game mode selected data attributed with DontDestroyOnLoad(transform.gameObject). Once I load my next scene it’s still alive but once I load any scene farther it is destroyed. How do I keep it going through? Attached is my script holding the gamemode.

public class gameMode : MonoBehaviour {

    // 1 = TAPTAP; 2 = TOW;
    public int game = 0;

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

Make sure you do not have any other script which destroys this object.

1 Like

Also verify that they aren’t a child of some other object that potentially got destroyed, as that should destroy them too.

mfw I found a previous line of code destroying it. Thanks for reminding me to check over my code.