Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
14
Question by kevinrocks_786 · Dec 09, 2015 at 04:18 AM · c#sceneapplicationapplication.loadlevelapplication.loadedlevel

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!

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArtOfWarfare · Dec 09, 2015 at 04:38 AM 0
Share

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?

avatar image kevinrocks_786 ArtOfWarfare · Dec 09, 2015 at 04:41 AM 1
Share

I tried what you said. No. I tried this:

 Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene()) ;

Also thanks for co$$anonymous$$g.

avatar image jarado9 · Jan 13, 2016 at 10:27 AM 0
Share

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?

avatar image Scripter05 jarado9 · Jan 27, 2016 at 02:36 AM 2
Share

It's probably too late now, but anyway, here is the code.

 if (Scene$$anonymous$$anager.GetActiveScene().name == "Name_Of_Your_Scene")
         {
             // Do something...
         }
avatar image jarado9 Scripter05 · May 05, 2016 at 11:11 PM 0
Share

Thanks, will be helpful

avatar image Le-Pampelmuse jarado9 · May 05, 2016 at 11:23 PM 0
Share

I've converted your answer to a proper comment. Don't post an answer if you don't have a solution to provide.

avatar image ggirgin · Feb 18, 2016 at 01:39 PM 0
Share

add also this;

using UnityEngine.Scene$$anonymous$$anagement;

3 Replies

· Add your reply
  • Sort: 
avatar image
44
Best Answer

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 .buildindexin 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

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArtOfWarfare · Dec 09, 2015 at 11:44 AM 2
Share

Odd that LoadScene can't actually take a Scene object.

avatar image Bonfire-Boy ArtOfWarfare · Dec 09, 2015 at 03:06 PM 1
Share

What do you mean by "a Scene object"?

avatar image ArtOfWarfare Bonfire-Boy · Dec 09, 2015 at 03:34 PM 1
Share

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...)

Show more comments
avatar image Nighthawk1029 ArtOfWarfare · Dec 29, 2015 at 09:32 AM 2
Share

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...

avatar image nevaran · Dec 09, 2015 at 02:55 PM 1
Share

Oh wow, thanks a ton - i didnt though of that! Was actually banging my head on how it was done xD

avatar image shahan nevaran · Dec 09, 2015 at 05:17 PM 0
Share

no problem. I was very confused as well especially since this is such an essential thing to do in my game lol.

avatar image Double_D · Dec 13, 2015 at 02:35 PM 1
Share

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;
avatar image shahan Double_D · Dec 13, 2015 at 08:16 PM 0
Share

Oh snap good addition. No joke I spun my noob wheels on that for a while too lol.

avatar image bunnybean · Apr 28, 2017 at 12:13 AM 0
Share

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"); } }

avatar image
3

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KennethUT · Jun 08, 2016 at 01:32 PM 0
Share

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;

http://docs.unity3d.com/530/Documentation/ScriptReference/Scene$$anonymous$$anagement.Scene$$anonymous$$anager.LoadScene.html

 import UnityEngine.Scene$$anonymous$$anagement;

solved the issue for me.

avatar image
2

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; "

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

50 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges