Question by
DeeLizard · May 24, 2017 at 12:28 PM ·
scenebuild settingsname
getting next scene name
so i need to get a string value of the name of the next scene in the build settings.
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
string nextSceneName = SceneManager.GetSceneByBuildIndex(currentSceneIndex + 1).name;
print(nextSceneName);
this feels like it should work however it is always returning "Null"
Comment
Tough luck , you can't like this because Unity doesn't really add the scenes in the scenelist unless they already been loaded thus you can't retrive them.Same goes for GetSceneAt(). $$anonymous$$inda distrurbing, and more disturbing they did not "fix" it yet. But if you don't really need the names use this to load next:
if(Scene$$anonymous$$anager.GetActiveScene().buildIndex+1 <Scene$$anonymous$$anager.sceneCountInBuildSettings)
Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().buildIndex +1);
else
Debug.Log("No more Scenes");
Answer by Giora-Guttsait · Aug 14, 2018 at 09:25 PM
I found the implementation from another answer here, but this is what I added to my code eventually:
public static string NameOfSceneByBuildIndex(int buildIndex)
{
string path = SceneUtility.GetScenePathByBuildIndex(buildIndex);
int slash = path.LastIndexOf('/');
string name = path.Substring(slash + 1);
int dot = name.LastIndexOf('.');
return name.Substring(0, dot);
}
This works for getting the names of scenes by buildIndex.