Get Scene Names In Build

It looks like quite a few people have asked how to do this, but the answers I found were all quite old (and seemingly excessively complicated).

So I’m just wondering if there’s currently a good way of getting a list of all scenes in the build. I’d like to make a stage selection list (three stage names are shown at a time, and you can scroll through them), so I need the scene names, of course. I didn’t think it would be such an ordeal just to get the stage names, but here I am, stuck. :confused:

Just curious as to why you’d need to grab them since you’ve (probably) created them – so you already know what scenes are in the game?

New scenes aren’t being generated (and named) dynamically, are they? In most games you’ll want scenes in some sort of order – chronologically in games where there’s a storyline that matters, or in ascending order of difficulty in games where levels stand alone. In either case, you probably don’t want to just grab a list of all scenes and show them to the player.

(Or maybe you do – just some food for thought.)

Jay

Well, my game is a 1v1 arena game in the vein of Towerfall, so there’s no story to be spoiled or anything like that. For a long time, you could just cycle through each stage with L1/R1 (and press X to start a match), but I have so many stages now that it’s getting tedious to go through them all if you want to play on a particular one.

But you do have a point: It’s not like new scenes are going to be added after the game is finished. I just wanted to try to do things more programmatically-- it seems like the “proper” way to do it.

Yes, I get that reasoning, for sure. :slight_smile: And it seems like there should be a way to do what you want – maybe someone smarter than us will come along…

Jay

1 Like

You should either get the TypeSafe asset ($13), which will let you do things like:

SceneManager.LoadScene(MyScenes.Level5);

Or you can create a big enum called LevelName, and keep adding the scene names to it as you go. Then you can do this:

public enum LevelName {
    Level1,
    Level2,
    MainMenu,
    OtherMenu,
}

SceneManager.LoadScene(LevelName.MainMenu.ToString());

@Jeffreyschooch: That would probably do it, but I was really hoping to learn about a simple built-in way of doing it. It’s weird to me that the scenes in build list is only accessible in the editor.