Slider reference lost when scene changes


I’ve been looking around trying to find an answer to this, but what I keep finding doesn’t give a definitive answer.

I currently have an Audio Manager game object that transitions between my two scenes (using DontDestroyOnLoad(gameObject);). The sound is adjusted by a slider on my first scene(the title screen) where I set up the reference to the Audio Manager’s script. Now when I run the game, I can adjust the volume using the slider, and the volume which I set is then carried over to the next scene(the actual game).

The problem occurs if I go back to the title screen. The slider’s reference is missing. Here are some images to help clarify:

Value is set and properly adjusts the volume.


After I go from the game to the title screen to readjust the volume.

How do I go about fixing this problem?

I believe you shall implement the AudioManager as a singleton object, in which case going back and fourth through scenes will keep the original object only.

private static AudioManager instance = null;
void Awake()
    if (instance == null)
        instance = this;