My game has a gameobject that has a DontDestroyOnLoad method. I also have a pause menu that can access the main menu which is in a difference scene. My problem is that if I access the main menu from the pause menu then the gameobject carries over into the main menu scene. Yet if I destroy the gameobject, when clicking the new game button which loads the main scene then the gameobject is still destroyed.
How would I go about resetting my main scene when I access it from the main menu so then the gameobject is created again?
Thank you.
DontDestroyOnLoad gameobject once destroyed is not reloading. How to reset scene to allow it reload?
Why would you destroy the first GameObject anyway? If I understand you correctly, you simply don’t want two of these GameObjects to exist. Why would you destroy the first one and try to use the new one if you could just destroy the new one and keep the old one?
private static NameOfThisClass singleton;
void Awake()
{
if(!singleton)
{
singleton = this;
DontDestroyOnLoad(this);
}
else
{
Destroy(gameObject);
}
}
(This pattern only is viable if you really plan to only ever have one of this kind of script at a time.)