I am having an issue with variables throwing ‘MissingReferenceException’ errors after I reload the same scene I just finished playing. I’ve found other Answers similar to this one but none of those answers have fixed this issue so I’m thinking I might have a different root cause.
I am running a scene that has a ‘Retry’ button and when the user clicks it I call Application.LoadLevel(“MyScene”). The first time my scripts access two specific objects I get the following:
MissingReferenceException: The object of type 'TrollAudioManager' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
I’ve verified that all the components and objects including the TrollAudioManager is being cleared and calling Start() again like normal (which does the re-grabbing logic as well).
To prevent this error I’ve added a null check and re-grab the component if it’s missing. However, if I then run a Play on that component (basically just a layer over a standard Audio Source), it plays two of the same clip with a single call to Play().
So the issue I’m struggling with:
-
If I don’t put a null check and re-grab the components I get a MissingReference (which technically should already be set from Start)
-
If I put in that null check/ grab; the audio plays twice as if there were two components of that type playing (I’ve verified there is only one after the reload)
I’ve also made sure to check that all my objects aren’t static and these objects aren’t being sent to DontDestroyOnLoad anywhere.
I know it’s hard to determine without the classes themselves, but any idea on a cause or solution?