Problem when loading a scene for the second time.

My game currently has two scenes.

Scene 1 is the Main Menu, Scene 2 is the level

When my game starts it loads Main Menu, I click to start the game, then it loads the level.

When the level starts, it spawns a bunch of objects, you play the game while its spawning etc. . . . All the while a timer is counting down.

When the timer reaches zero, I have the timer script push me back into the Main Menu using

` Application.LoadLevel(0); `

The game then returns to the Main Menu.

My problem is this: After the game returns to the Main Menu, if I click to start my level again, the level loads, the timer begins decaying down to zero, but none of my objects respawn (I can't play the actual game).

All that happens the second time the level loads is the timer counts down and then returns me to the main menu.

Where should I look to find what is causing this problem? To me it seems that once the scene is loaded again, it should simply behave the way it did the first time it was loaded. Why wouldn't this be happening?

If you're using any static variables, get rid of them and use regular variables instead. Either that or you have to reset them manually.

For me I was using static events, which even though everything that was subscribing was unsubscribing it (and being destroyed) - it was still referencing the first instance of it from initial scene (which no longer existed!!)
Make sure you put
void OnDestroy()
{
EventName = null;
}

for every static event in that script.

Do you have any objects that have DontDestroyOnLoad called on them?

I found this old thread healpful and found out I had a static variable issue. The lesson here is that the lifecycle of static variables is the application and not the scene, and this is why static variables in MonoBehaviours need to be initialized in Awake() or Start(). If a static variable is not initialized in one of those places, it will get initialized only on class load (first time the class is referenced during the whole application lifecycle), and if the MonoBehaviour is reloaded (when a new scene is loaded), the variable will retain whatever value it had when the old scene was unloaded as the class is not reloaded.