GameObject - missing reference - strange behaviour

Ok guys. Here’s the issue. Here’s my project setup. Starting the game in the MainMenu , from there loading a new scene, going to the GameScene, all good all fine, everything works good, end game conditions are met, the MainMenu scene is loaded again, from there AGAIN i go to a new game. From here things start to act wierd. I have a GameObject called “X” let’s say, that GameObject has a child called “Y”, in the Start() - “X” get’s a reference of “Y” using GetChild(), in Debug mode everything looks good, no null reference, the object loaded without a problem, nothing, but when an event handler in “X” tries to access “Y” says that the object is destroyed and that the reference is missing which is wierd. As I said , first run of the game, no exception is thrown, but the second run this is the behaviour I get. The game works good even after the exception! The event handler enables and disables the gameObject that throws an exception without a problem! But why that exception? Am I missing something related to Scenes? Thank you in advance, appreciate.

GameMananger.Instance.GetPlayer(_side).SomeEvent += EventHandler;

Where are you removing the event registration from SomeEvent? I assume that your GameManager never gets destroyed when you’re switching scenes. This means it continues to hold a reference to that EventHandler method. When the event gets triggered it tries to call all of the registered handlers. When it gets to this object (which has been destroyed as far as Unity is concerned, because of the scene reload) you’re getting the error.

So you need to add an OnDestroy method so you can remove the event handler when the object is destroyed.

void OnDestroy()
    GameMananger.Instance.GetPlayer(_side).SomeEvent -= EventHandler;