- Home /
Load Scene from within folder?
If I have a scene(named 'Level1.unity'), saved within a subfolder of assets(named 'NightWorld'), and added it to the Build Settings(listed as 'NightWorld/Level1.unity'), how can I load that using Application.LoadLevel()? I tried Application.LoadLevel("NightWorld/Level1.unity"), but got 'Level couldn't be loaded because it has not been added to the build settings.' Does anyone know why it isn't loading the level even though it clearly shows it in the Build Settings? Do I not just use folder-name/scene-name?
I think that loading scenes directly is not possible, I could be wrong though. Why not just name them NightWorld1, NightWorld2 etc. $$anonymous$$aybe you could have a 'world' string and a level number variable, combine the two into a string, and load that?
Answer by InvincibleCat · Jan 13, 2015 at 12:49 AM
Heu nope... just Application.LoadLevel("Level1");
Answer by DFortun81 · Jan 13, 2015 at 12:16 AM
So long as you include the scenes in your build via the Build Settings, you can do the following to load your scene:
public static void LoadLevel(string name, int sublevel)
{
Application.LoadLevel(string.Format("{0}_{1}", name, sublevel));
}
You could then call it like so:
LoadLevel("NightWorld", 1);
And it would load the level called "NightWorld_1" if it exists. Not sure if that would throw an exception if it ever fails, but it might be a good idea to surround your call to the function with a try / catch and handle it appropriately with UI messing or something.
EDIT: For more clarification, the way that the level is included in the game is by its name, not its full path. Let's say your level is stored like so: "Levels/NightWord/Level1.unity", when you go to load the level in Unity, all you need to type is "Level1". Unity removes the full path of the level. (This is both a blessing and a curse, I'm afraid.)
Your answer
Follow this Question
Related Questions
Scene could not be loaded even though it is in build settings 0 Answers
Application.Loadlevel loads incorrect scene. 0 Answers
"Scene couldn't be loaded because it isn't added to the build settings" but it is? 1 Answer
How to use one object selected from previous scene to the current scene ? 1 Answer
Cannot close/unload a scene that is open in editor during playmode (using C# code)? 3 Answers