I Click play on my 2D Game while in the menu, I then click the Settings button to switch to the settings scene, and it says my AudioSource is destroyed and that I’m still trying to use it. I check the GameObject that I assigned the AudioSource to and its not attached. It also doesn’t let me drag the AudioSource into the GameObject. If I click play while already on the settings scene, nothing bad happens. That leaves me to the conclusion of it not working because of DontDestroyOnLoad which only activates after switching scenes and is used to not restart sound clip after switching scenes.
Hi @Bikini_Carrot,
Welcome to our community!
Check if your “singleton” calls gameObject.SetActive(false);
in the same if-block where Destroy(gameObject);
gets called. If there isn’t that line of code, add it.
Did this fix it?
See also:
- Forum User Guides : How to mark a topic as solved
Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.
You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.
The is an else code block with the Destroy method. Add the line with SetActive which I suggested in my previous answer. Then save your code and test your game again.
Hope this helps
See also;
- Forum User Guides : How to apply code formatting within your post
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.