Search Unity

how to get the loaded scene name?

Discussion in 'Scripting' started by hellocp, Apr 25, 2011.

  1. hellocp

    hellocp

    Joined:
    Apr 25, 2011
    Posts:
    3
    i use the function 'Application.LoadLevelAddtive' load several scenes, how can i get all the loaded scenes' name?
     
    ocimum likes this.
  2. Yorick2

    Yorick2

    Joined:
    Jan 24, 2009
    Posts:
    297
    You can't get a list of all the loaded scenes but you can get the current loaded scene with:
    Application.loadedLevelName

    You could just make a list yourself and update it every time you call Application.LoadLevelAddtive
     
    ocimum likes this.
  3. hellocp

    hellocp

    Joined:
    Apr 25, 2011
    Posts:
    3
    fine, thanks Yorick
     
    ocimum likes this.
  4. ocimum

    ocimum

    Joined:
    Apr 19, 2015
    Posts:
    12
    this did it! Thx @Yorick2

    I also created a solution for getting the scene while inside an `Editor` script. This way you will get the name without any suffix at the end:

    Code (CSharp):
    1. public static string HelpGetSceneName(){
    2.         string[] strScenePathSplit = EditorApplication.currentScene.Split('/');
    3.         string[] strFileWithExtension =
    4.              strScenePathSplit[strScenePathSplit.Length - 1].Split('.');
    5.         string sceneName = strFileWithExtension[0];
    6.         if( sceneName == null ){
    7.             Debug.LogWarning("Scene name not Available");
    8.         }
    9.         return sceneName;
    10. }
     
    Last edited: Jan 26, 2016
  5. jasonjoh

    jasonjoh

    Joined:
    Jul 30, 2015
    Posts:
    2
    As of Unity 5.3 this is now

    Code (CSharp):
    1. SceneManager.GetActiveScene().name
    For example:

    Code (CSharp):
    1. Debug.Log(SceneManager.GetActiveScene().name);
     
    MilanTheNoob, Lohaz, rogaroga and 4 others like this.
  6. MilanTheNoob

    MilanTheNoob

    Joined:
    Dec 1, 2015
    Posts:
    1
    Make sure if you use this then enter at the top of the script

    Code (CSharp):
    1. using UnityEngine.SceneManagement
    [/QUOTE]
     
  7. HyunsDaeri

    HyunsDaeri

    Joined:
    Jun 11, 2019
    Posts:
    1
    Hello everyone. I'm Korean, I know this question.

    Scene scene = SceneManager.GetSceneByName( sceneName );
    if (scene.isLoaded == true)

    You can check it, Did I help You? ^_^
     
  8. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,531
    Mind you, this thread is old. The original post is from 2011 and predates the existence of 'SceneManager'.

    Since then jasonjoh has updated how you would do this using SceneManager back in 2016.