- Home /
Slider reference lost when scene changes
Hello!
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?
Answer by rh_galaxy · Dec 28, 2021 at 06:53 PM
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()
{
//singleton
if (instance == null)
{
instance = this;
DontDestroyOnLoad(this.gameObject);
//Init();
}
else
{
Destroy(this.gameObject);
}
}
Thank you for the quick response. I have the AudioManager set up as a singleton already and it still doesn't work. I was thinking, is there a script I can add to the slider that if the value changed reference is null or missing, it'll find the Audio Manager?
Your answer

Follow this Question
Related Questions
How to copy a scene to a new unity project 3 Answers
Building Player including assets not referenced in scenes included 2 Answers
How do I reference something from another scene? 0 Answers
Cross Reference MultiPurposeCameraRig 0 Answers
i want the player to match 5 items correctly before next scene appears. 1 Answer