- Home /
Unity 5.3 How to load current level
Hello, before Unity 5.3, I could do
Application.LoadLevel(Application.loadedLevel);
But now it's something weird with SceneManager. I've read documentation but nothing. How do I get the current scene and load it (Unity 5.3f4)?
Thanks!
In my code, I refer to the scene by name. That obviously won't work if you need to use this script between multiple scenes though. In the answer that you commented on (thus bringing me here), I had suggested what appeared to be the right way to programmatically deter$$anonymous$$e the current scene... Did that not work?
I tried what you said. No. I tried this:
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene()) ;
Also thanks for co$$anonymous$$g.
The one I having difficulty figuring out is how to check if loaded scene has a certain name, e.g before 5.3 if (Application.loadedLevelName == $$anonymous$$ainScene) { do something!! }
anyone can help with this?
It's probably too late now, but anyway, here is the code.
if (Scene$$anonymous$$anager.GetActiveScene().name == "Name_Of_Your_Scene")
{
// Do something...
}
I've converted your answer to a proper comment. Don't post an answer if you don't have a solution to provide.
add also this;
using UnityEngine.Scene$$anonymous$$anagement;
Answer by shahan · Dec 09, 2015 at 09:59 AM
someone in the #unity3d irc chat helped me figure out it is this:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
GetActiveScene()
returns the current scene object then you can use .name
or .buildindex
in LoadScene()
http://docs.unity3d.com/ScriptReference/SceneManagement.Scene.html
*Edit: Addition from Double_D you need:
using UnityEngine.SceneManagement;
Here's an example script of mine: https://github.com/sia/Khomaniac/blob/master/Assets/_Scripts/FallDeathRestarter.cs
Odd that LoadScene
can't actually take a Scene
object.
I'm not sure what there is to be confused about... Scene$$anonymous$$anager.GetActiveScene()
returns a Scene
object. You have to quite a bit more rep than I do so I'm not sure how you wouldn't understand that. Perhaps it's not called an object in C#? I've only been using the language for two weeks now, but it seems pretty similar to ever other OO language I know (Java, Python, C++, etc...)
This worked for me thanks! but for some strange reason the lighting in my scene changed weirdly. At first the scene is lit really well and then after reset the lighting goes down tramatically and I have no idea why...
Oh wow, thanks a ton - i didnt though of that! Was actually banging my head on how it was done xD
no problem. I was very confused as well especially since this is such an essential thing to do in my game lol.
Thanks for the help, but I still spun my n00b wheels for a $$anonymous$$ute on this one, because you must include the following line at the top of your script in order to use the Scene$$anonymous$$anager:
using UnityEngine.Scene$$anonymous$$anagement;
Oh snap good addition. No joke I spun my noob wheels on that for a while too lol.
Hi, I was curious about how to reference a level in code. I bolded what I need to fix. I need to be able to have the player move up a level. Thank you!
void Update(){
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && count >= winneed && Scene.isLoaded("first thing")) {Application.LoadLevel("second thingy"); }
if(Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && count >= winneed && Scene.isLoaded("second thingy")) {Application.LoadLevel("third thing"); } }
Answer by djindepth12 · May 16, 2016 at 10:21 PM
If "using UnityEngine.SceneManagement;" does not work for you in javascript try:
import UnityEngine.SceneManagement;
That worked for me.
This helped me for my JavaScript updates. The documentation is incorrect at the bottom of the page under Description where it states:
Note: In JavaScript add:
using UnityEngine.Scene$$anonymous$$anagement;
import UnityEngine.Scene$$anonymous$$anagement;
solved the issue for me.
Answer by Founasek · Oct 02, 2016 at 07:40 AM
This works 100%!
public void Reload()
{
int scene = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(scene, LoadSceneMode.Single);
Time.timeScale = 1;
}
Don´t forget to add " using UnityEngine.SceneManagement;
"
Your answer
Follow this Question
Related Questions
Menu on Android Application 1 Answer
problems with continuous audio between scenes 1 Answer
Teleport to next scene on trigger 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers