C# SceneManager.LoadScene does NOT reset all variables?

Hi !!!

I added a button in my game, and if you click it, it reloads the level. * SceneManager.LoadScene(sceneName);*

However,

I realized it does not Reset all scripts etc. I does reload the scene, but a bunch of the variables on other scripts are not being reset?

Example, a generator of gameobject acording a time interval, does not generate when reset scene or a gameobject with a animation when reset the scene, dont show the animation.

What do I do/Look for. To Reset everything in the scene as if it was the first time I opened it (including the other scripts)
Thank you!

When you reload the scene it should destroy all the existing game objects and their attached components and reset them to their original values, unless there is something keeping them there. Things you might have done:

Any static variables will stay. (public static string hello = “hello”; )
Anything marked with [DontDestroyOnLoad] will stay.
Non-monobehaviour classes that are referenced by either of those above things will stay.

Thanks for answering
I do not have any static variables or any DontDestroyOnLoad,
And I do not have referenced variables of this type either.

I do not understand what happens, it’s supposed to reload a scene, it reload all,
Variables, animations, audios, etc. And this should start as the first time
Charge, but this is not my case !! I do not know what to do, I go crazy, and I do not know where to look
It would be good if someone showed me a crumb of bread

Thank you

I am facing the same issue…

i think it’d be helpful if u post some code example of your project.

Yep, show us the code on the script you’re having trouble with and we might be able to tell you more. It could also be the gameobject, sometimes assets you use from the store may include their own scripts that keep stuff around.

1 Like