How to reset a static variables on loading a scene [SceneManager.LoadScene(NameofScene)].
How to reset a static variables on loading a scene [SceneManager.LoadScene(NameofScene)]. I tried to initialize variables in Start function or in Awake function but i find bad result.
I think a simple solution would be to write a static function that will reset the values and call it right before (or after) you load the scene.
Answer by Determined · May 01, 2017 at 04:20 PM
You can use SceneManager.sceneLoaded delegate and change the value of the variable in that deligate function.
Here's a link on how to use SceneManager.sceneLoaded: link
Answer by luqadastudio · Dec 09, 2021 at 08:32 AM
Example if you have static variable you can set all the static variables to 0 on Awake:
private void Awake() { diceSideThrown = 0; player1StartWaypoint = 0; player2StartWaypoint = 0; }
Your answer
![](https://koobas.hobune.stream/wayback/20220612120758im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
LoadScene in UnityScript 1 Answer
Unload all scenes except one 1 Answer
Saving gameObjects state on load 0 Answers
"Method arguments are incompatible" when loading a scene 1 Answer
Moving to Next Level on collision 1 Answer