- Home /
How can I check what levels are included in the build in code?
I have a text field on my main menu for loading levels quickly during build testing, but I would like to add a check so if the user types a level name incorrectly instead of throwing runtime errors and staying on the menu it can instead tell the user that they entered an invalid string.
I know that I could do this with a switch and manually code each level into it as more are added, but that's the opposite of modular.
Answer by Screenhog · Oct 05, 2012 at 05:09 PM
Oddly, there doesn't seem to be an array of level names that I can find.
The best solution I can think of is to load a level by number instead of by name. Application.levelCount gives you the total number of levels loaded, so someone could type in their level by ID number (and also check if someone types in a number that's above the limit).
I figured there wouldn't be, that would be too easy. Guess I'll just have to come up with a different solution when finalizing the game.
The info about the scenes is accessed through EditorBuildSettings.scenes. Unfortunately, it's an Editor script, and I don't know how to access information from within the editor to be used in-game.
Guess that means there is no way to do it during runtime. I keep finding editor functionalities I wish I could use during gameplay...oh well.
Not unless there's a way to save the names from the editor, and then access them at runtime. A text file, maybe? It's beyond my knowledge, unfortunately.