Can't access an object which is in DontDestroyOnLoad
Hello guys, first of all i want to say that i am a complete noob concerning unity programming therefore i would gladly appreciate your help.
So my problem is that i have a background music object in DontDestroyOnLoad so my audio file gets played seamlessly when switching scenes. I also have a toggle mute button in one scene which works exactly like it should when i start the game with this specific scene. But when i switch scenes and come back to that one specific scene i can't use my toggle mute button anymore and get the error: "The object of type AudioSource has been destroyed but you still try to access it". I know the reason for this is that my backround music object is in dontdestroyonload. How can i fix it? Or how can i access this background music object which is in DontDestroyOnLoad?
Please help me i am kinda lost right now. :)
$$anonymous$$y guess is that the mute button is looking for the audio file that was already present in the scene which got deleted. It's not looking for the one in the dontdestroyonload object.
Answer by Moogstir · Oct 01, 2017 at 01:48 PM
I have almost the same problem, im trying to access my gameobject Player with DontDestroyOnLoad, but its not working. i want to still be able to access the player when my scene changes. @Kleinstudios
Your answer
![](https://koobas.hobune.stream/wayback/20220612125803im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Destroyed object in DontDestroyOnLoad does not recreate in its main scene 0 Answers
Can I create a scene DontDestroyOnLoad in editing mode?? 0 Answers
Dropdown menu: how to make colour change across multiple scenes 0 Answers
Singleton GameManager with DontDestroyOnLoad acting weird 0 Answers
dontDestroyOnLoad doesn't work as expected with scene navigation 0 Answers