AddListener bug

Video of the problem: http://sendvid.com/sv5kiwah
Script: http://pastebin.com/8DNRYPBp

I have a problem that occurs with a singleton gameobject called _OptionsController. If I load the “options” scene directly, I can adjust options with no problems (mute music and unmute it), but when I click “back” button and revisit the scene I no longer have the ability to control the options**.**

I’m able to understand that when I load the scene “options” from another scene, functions that I add through AddListener - for example “void ToggleMusic(bool on)” are not being triggered by my click anymore. Debug.Log shows that it finds buttons, but I have no clue why it doesn’t trigger functions anymore :confused: Has anyone got any idea?

that script is only running awake once, when it is first created. You are using the dontdestroyonload option so the script isn’t dropped when a scene is loaded, so awake isn’t going to be called again.

Since you are linking things up from the functions being called in awake, once the buttons (which I’m assuming aren’t being retained between scenes) are destroyed by subsequent scene loads you are going to never establish the listeners again.

1 Like

Tnx dude, now I used function OnLevelWasLoaded and it seems to be working fine :smile: