MissingReference When Reloading Scene

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:

  1. 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)

  2. 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?

I figured out the answer was due to setting events. I am using the ‘Dialoguer’ asset from the store and noticed the issue kept happening in the same event handler. After looking through the base code I found the function ‘ClearAll()’ which simply sets all the event handlers to null. Doing this before I re-set them releases those references to the old handlers and properly re-attaches the latest events.

I’m not great with event handlers but from what I gather they act almost like a pointer so simply trying to point them somewhere else without releasing what they point to currently was my issue.