Why does Audiosource.PlayClipAtPoint gives me a MissingReferenceException when loading a new scene?
As the title says. I've been using AudioSource.PlayClipAtPoint to play a sound effect when certain scene objects are destroyed. Each object plays it's own SFX this way. I'm not playing it in onDestroy, mind you: PlayClipAtPoint is called by the object's logic before calling Destroy(gameObject).
It works well if I clear the level as intended and destroy all the things that are supposed to be destroyed to win. However, in cases when I either get a game over (thus loading a game over scene before the level is cleared), or when I quit the testing session mid-level, it occasionally gives me that error. It's not even consistent.
So, my questions are A - why? and B - What can I do to fix it? It's a static method, I can't (nor should need) to check if there's an AudioSource instance. Thank you in advance!
Oh, I almost forgot: I'm using Unity 2019.3.1f1
Your answer
Follow this Question
Related Questions
Missing Reference Exception... please help, I am new to this! 2 Answers
Unity error The object of type 'Preview' has been destroyed but you are still trying to access it. 0 Answers
Unable to convert classes into dex format. Using only Google Cardboard in Unity (Mac) 5 Answers
Why unity crashes with my code ? 1 Answer
Trigger code gives error 0 Answers