AudioSource missing reference after SceneManager.LoadScene

Hi there,

I am encountering the weirdest issue, that I will try to break down in the easiest way possible.
My game is a one scene only. Many objects in this scene, all with different components in them. The game runs fine in editor, compiles just fine as well.
When I run the game (regardless of the platform), everything is perfect, except that, when the player dies I use SceneManager.LoadScene() to reload the current scene.
However, while level loading works fine, I suddenly gets my audio source on one of my object to throw a missing reference (component destroyed) when I try to access it in my script ( as = GetComponent() ).
I checked in the editor after reloading my scene and the audio source is definitely there.

If I quit the game completely and re-launch, everything is fine again.
I tried my ways of tricking the engine to re-load completely (for example, I load a n empty scene which purpose is to load the main scene again) to no avail.
Note that this is happening in the editor AND on the final build.

Anyone already encountered these? I assume there is a memory issue.

Fixed it. Using delegate to listen to events can be tricky. You really need to unregister when objects are destroyed.
Keen to get an explanation if someone can provide it :slight_smile:

My situation: I have a prefab with an AudioSource attached. When i instantiate the prefab at runtime i noticed that the AudioSoure would get removed from the prefab. What I did to overcome this issue is to add a second AudioSouce, because i noticed that the first one gets removed and the second one stays with the prefab upon instantiation. Hope this helps!