How to fully restart a game

My game keeps restarting after resume, but not fully, the gameobjects in “dont destroy onload” were still there, and they make the game runs not correctly.

Any GameObjects that get added to DontDestroyOnLoad will stay there until you call Destroy() on them. One way to handle this would be to maintain a list of all GameObjects marked as DontDestroyOnLoad that you can easily delete all at once.

Here’s an example (shamelessly taken from here):

public static class DontDestroyOnLoadManager
{
    static List<GameObject> _ddolObjects = new List<GameObject>();

    public static void DontDestroyOnLoad(this GameObject go) {
       UnityEngine.Object.DontDestroyOnLoad(go);
       _ddolObjects.Add(go);
    }

    public static void DestroyAll() {
        foreach(var go in _ddolObjects)
            if(go != null)
                UnityEngine.Object.Destroy(go);

        _ddolObjects.Clear();
    }
}

Hope this helps!