- Home /
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.
Answer by Josh Naylor · Oct 03, 2014 at 10:38 AM
Use
Application.LoadLevel(Application.loadedLevel);
Hi Zack. This is not a problem. The light will be there when you make a build and run it. To fix it in the editor you can however do this: To fix it in the Editor, go to Window -> Lighting -> Lightmap Tab -> Disable Continuous Baking -> Press Build to bake the lighting once manually.
Hello, I need help @$$anonymous$$aker$$anonymous$$ I cant find how to turn off continuous baking in the settings (I'm Using Unity 2017.3)
Answer by mikiqex · Dec 21, 2015 at 01:11 PM
UnityEngine.Application.LoadLevel is obsolete, use SceneManager.LoadScene:
using UnityEngine.SceneManagement;
...
SceneManager.LoadScene("Scene_Name");
It's not working on my computer. Is there something wrong with this code? By the way, Hurts is a function that is called when the enemy sends a message to the player (I'm pretty sure that the problem isn't in there, because I already used a Send$$anonymous$$essage for something else in the game and it works fine)
using UnityEngine;
using System.Collections;
using UnityEngine.Scene$$anonymous$$anagement;
//code and stuff
void Hurts (int amount) {
health -= amount;
if (health <= 0) {
Scene$$anonymous$$anager.LoadScene("dungeon 1");
}
}
It says "The type or namespace name 'Scene$$anonymous$$anagement' does not exist in the namespace 'UnityEngine'. Are you missing an assembly reference?"
Do you use the latest Unity? If not, it's possible Scene$$anonymous$$anagement isn't present in yours version yet.
Sorry this is 2020 lol but is your scene in build settings? If not drag your scene into the scenes area
Actually, to restart the CURRENT scene, you would do:
Scene$$anonymous$$anager.LoadScene(GetActiveScene().name);
Thanks. You forgot a Scene$$anonymous$$anager.
though.
Scene$$anonymous$$anager.LoadScene (Scene$$anonymous$$anager.GetActiveScene ().name);
using UnityEngine.Scene$$anonymous$$anagement;
Scene$$anonymous$$anager.LoadScene (Scene$$anonymous$$anager.GetActiveScene ().buildIndex);
This is the correct way because this method takes "int" type parameter and you have to sure one thing that your all scenes have been added in build Settings.
Answer by Cubemann · Apr 16, 2021 at 07:35 PM
Application.LoadLevel.(Application.loadedLevel); or SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 0); I don't know if this works, but SceneManager.LoadScene(SceneManager.GetActiveScene();
Your answer
![](https://koobas.hobune.stream/wayback/20220613164314im_/https://answers.unity.com/themes/thub/images/avi.jpg)