How to prevent Unity4.6 Toggle button loosing its state when jumping between scenes?


I have a Singleton MusicManager what offers sounds and music to a game, menus, buttons etc. I tested today Unity3d 4.6 new Toggle-button and somehow it is working. If I turn sounds off in my option menu and go to play a game and come back to option menu, the image is back in default state (music on). I am using my MenuManager.cs and it is calling singleton Musicmanager, How can I prevent this? Is there way to tell Unity that don’t destroy and instantiate options-scene again when jumping between scenes or could I somehow programmatically change the state/image of the toggle-button to be right?

EDIT: The weirdest thing is that according to the Unity Log, when I come second time to Option screen, it goes automatically MusicManagerSingleton and MenuManager’s ToggleMusic() methods even if I haven’t touch the whole button? My usecase is that when I go first time to options and mute the music, everything is working fine, BUT when I come back there without touching the button,music starts and mute/sounds Toggle button is in state true.


Unity calls automatically ToggleMusic()-method as well and that was the reason. I added this line and everything started to work:
if (toggle.isOn != MusicManagerSingleton.Instance.musicOn())

public class MenuManager : MonoBehaviour {

	public bool musicOn;
	public AudioClip musicClip;
	public UnityEngine.UI.Toggle toggle;

	public void Start ()
		toggle = GameObject.Find("MusicToggle").GetComponent<UnityEngine.UI.Toggle>();
		toggle.isOn  = MusicManagerSingleton.Instance.musicOn ();
		Debug.Log ("0. START() MenuManager musicOn in ToggleMusic()--->" +toggle.isOn);

	public void ToggleMusic() {
		MusicManagerSingleton.Instance.toggleMusic ();
		//toggle.isOn = MusicManagerSingleton.Instance.musicOn ();
		Debug.Log ("1. AFTER TOGGLING MenuManager musicOn in ToggleMusic()--->" +toggle.isOn);
		Debug.Log ("2. AFTER TOGGLING MenuManager musicOn in ToggleMusic()--->" +MusicManagerSingleton.Instance.musicOn ());



public void ToggleMusic() {

	if (toggle.isOn != MusicManagerSingleton.Instance.musicOn()) {
		MusicManagerSingleton.Instance.toggleMusic ();




You could use the PlayerPrefs to store state between scenes. When you alter the value in the options, set the value in PlayerPrefs. When you come back to the option menu, get the last recorded values from PlayerPrefs.

You can declare a static variable in your MenuManager to store your toggle state before loading the new level and in your MenuManager.Start you will set the toggle state yourToggle.isOn = MenuManager.yourVariable (static variables persist even if you change level).

There are multiple ways to approach this. Choose the one that fits. In the order I would suggest they are:

  • Have the button check the sound manager state in OnEnable
  • Use DontDestroyOnLoad to maintain the same button
  • Tie an event to the change in your sound manager. Update the button every time the event fires