1
votes

I have a simple script that reloads my scene. The function is called by a button OnClick() event.

public void ReloadScene(){
    SceneManager.LoadScene (SceneManager.GetActiveScene ().name);
}

This function should restart the current scene. It does what I expected it to, but with one problem: most scripts don't work.

The only scripts that work are the Audio Source, and another simple script that I have written. I get no errors when I just press "play".

I am using Unity 5.6.0b9 Personal.

1
hey Yummy, it's possible you're facing the single biggest confusion in Unity: you probably need to do this - stackoverflow.com/a/35891919/294884Fattie

1 Answers

1
votes

Reloading a scene does reset the variables unless you are using static variables. A new instance of an object would reset each object to their initial state. Static variables are not destroyed as they do not belong to an instance. You can reset those manually.

DontDestroyOnLoad() is a little different. It asks Unity not to destroy an object if a new scene is laoded. So these objects won't get destroyed (reset).

If you have dynamically added some scripts, then they will get destroyed as well. Unless, they are added to a DontDestroyOnLoad() parent.