Reload a scene and resetting all variables

I want to reset my scene. Nothing new but I want to reset all variables. In the web i found every time the same Application.loadLevel (xx);. But it doesn't reset all variables! One guy sad use singletons but i don't know how they work and what they do. Help please Cery

Ps: sorry for bad english

Reloading the scene should reset all the variables unless you are using static variables because logically creating a new instance of every object would reset its values to their initial state.

`Static` variables on the other hand are not destroyed because they are part of a class, not an instance. You have to reset these manually.

`DontDestroyOnLoad()` is a little different. It tells Unity not to destroy an object when you load a new scene. So these objects won't be reset either because they aren't being destroyed and recreated.

The only way to reset them is just to manually go through and turn the variables back to some initial state. It is your choice how you do that. You can either save all the initial values, or copy the values over from a newly instantiated class.

I Have the same problem with a part of my code which doesnt execute the next time when I reload the Scene, and when I revise the code I didnt have any static var ( :smiley: ).

But In my case, and I have to tell you due to other have the same case and doesnt have static variables, It was with a variable that when I finish to use it I put it to Mathf.Infinite value, and when the reload scene happens and the Start function tried to make this var again to Time.time … it looks that it doesnt work :S

So, I rewrite the workflow of the code to make the same things with other strategic and eliminate the Mathf.Infinite.

You can just create a new script like “lvl01_Updates”. Where in the start script you place your variable to 0 or false. You don’t interact with the code but its running in the background when you load the scene.

If that answers your question