Search Unity

SceneManager needs GetSceneNameByIndex()

Discussion in 'Scripting' started by cory_munky, Aug 23, 2016.

  1. cory_munky

    cory_munky

    Joined:
    Dec 10, 2014
    Posts:
    66
    I want to write something like "errorCode LoadSceneByName(string sceneName)". Our app uses asset bundles.

    When my gameplay engineer passes me a sceneName, is that scene in a bundle, is it in the build list or maybe neither? I can figure out for myself if it's in a bundle using the bundle manifest. So, is it in the build list or do I need to report an error? SceneManager offers no solution. I can only charge ahead and call "void LoadScene(sceneName)" and hope that no one will ever misspell or even mis-capitalize any scene name slightly wrong.
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    couldn't you do something along the lines of

    Code (csharp):
    1.  
    2. Scene sceneToBeLoaded = SceneManager.GetSceneByName(<...sceneNameVar...>);
    3. if(sceneToBeLoaded.IsValid())
    4. {
    5. // load the scene by name
    6. }
    7.  
    ?


    edit: actually for that approach it's a shame there isn't a LoadScene overload that accepts a Scene as the first param :D