So i have an UI toggle button, which pressed, mute or unmute the audio. Now this toggle is a child of Canvas. DontDestoryOnLoad function keep only the root of hierarchy and not the child. I can’t move the toggle out of canvas because it will not be visible, but also I can’t put the DDOL on canvas because I don’t want to be seen in the main scene. Is there a way to save the state of toggle, to work in every scene? If not something like putting undearneath the canvas of the main scene?
I don’t know if this comment will be seen, but i solved the issue. So I assigned the OnDestroyOnLoad to the canvas. Whenever i hit the play button i make the component of the canvas false like this: CanvasObject.GetComponent().enabled = false (it is important to make the component false and not set the canvas false, because you ca not do anything if its false);. After that, with a static bool variable let’s say isMenu, whenever i press the button Menu, isMenu become true. So, in the OnDestroyOnLoad script, make an Update method and check if the isMenu == true, now you can set the canvas true wih the above line. Believe me, it is one of the easiest way to do it. I hope that you understand something and it will be helpful for the future generations, not to waste 15 years, figuring this out on their own. I am not the hero you deserve, but the one you need.