How to restart scene properly

Hey. So I know that I could simply restart my scene by getting the name of the scene and putting it in some script, but I want to use a script that will work on multiple scenes that checks the current scene and restarts it without requiring a scene name. If someone can provide a simple script that performs this action, I will be more than happy.
Cheers.

4 Answers

4

UnityEngine.Application.LoadLevel is obsolete, use SceneManager.LoadScene:

using UnityEngine.SceneManagement;
...
SceneManager.LoadScene("Scene_Name");

Actually, to restart the CURRENT scene, you would do: SceneManager.LoadScene(GetActiveScene().name);

Use

Application.LoadLevel(Application.loadedLevel);

Thanks heaps

deprecated code!

Hello, I need help @MakerDavid I cant find how to turn off continuous baking in the settings (I'm Using Unity 2017.3)

It is deprecated now. Use SceneManager instead.

At the top of your file add:

using UnityEngine.SceneManagement;

When you want to restart your scene add:

SceneManager.LoadScene(SceneManager.GetActiveScene().name);

That’s it!

thank you!

Application.LoadLevel.(Application.loadedLevel); or
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 0);
I don’t know if this works, but
SceneManager.LoadScene(SceneManager.GetActiveScene();

It works, but iu just need to add a ".name" at the end of GetActiveScene. Just like this: SceneManager.LoadScene(SceneManager.GetActiveScene().name);