Restart a scene and reset all values?

I would like to restart my current scene or start another scene from scratch after playing it once before. When I use this code:

SceneManager.LoadScene (SceneManager.GetActiveScene().buildIndex);

The scene restarts but the values and all the previous events are exactly the same ( player starting position, enemies number, score, etc) also the lighting gets messed up. Is there a way to restart a scene from scratch or do I have to write my own function that takes care of that?

Static variables are not reset but non static (normal) variables should reset as well as the game objects.

Just to test to try to figure out what is going on you could try loading another scene or even a real quick loading scene if that seems to help you.

As for static variables, the only safe course of action is to initialize them each time the scene is loaded.

2 Likes

Hopefully the previous posters comment can help with variables. The lighting is a different issue.I remember experiencing this same issue and it confused me. I think this is the exact post I found back then, too lol

first hit for me in google :slight_smile:

1 Like

Thank you both for answering. Yes, I did have some static variables in my “Level Manager” object that controls different aspects of the game, re-initializing them in “Start” function helped.

And that link to the lighting problem definitely helped.

Cool. Glad to hear it.