Scene IS added to build settings: "Scene couldn't be loaded because it has not been added to the build settings"
Hi everyone,
I am getting the error "Scene couldn't be loaded because it has not been added to the build settings" despite the fact that the scene IS in the build settings, and ticked.
My code to load the scene is as follows:
void genericLoadScene(string sceneName, List<string> parameters)
{
SceneManager.LoadScene (sceneName+"");
}
As you can see by the presence of sceneName+"", I am definitely passing it a string, not a variable name. The error occurs with specifically this scene. All other scenes work fine.
![Image of Build Settings][1]
I have checked the string that I am passing in to ensure it is correct many multiple times. What am I doing wrong, please?
have tried reordering the scenes* [1]: /storage/temp/62590-screen-shot-2016-01-25-at-152122.png
try loading it by number ins$$anonymous$$d of the name.
It loads by number absolutely fine. Then I can compare the name string that I am passing in with the name of the correctly loaded level, and they are equal... Which still begs the question: Why won't it load with the name only?
If I change my genericLoadScene method to
void genericLoadScene(string sceneName, List<string> parameters)
{
Debug.Log ("Loading Scene "+sceneName);
Scene$$anonymous$$anager.LoadScene (14);
Debug.Log ("Scene Loaded "+Scene$$anonymous$$anager.GetActiveScene ().name + "");
if (sceneName == Scene$$anonymous$$anager.GetActiveScene ().name) {
Debug.Log ("Scene names WERE equal!!!");
} else {
Debug.Log ("It turns out "+sceneName+" is not equal to "+Scene$$anonymous$$anager.GetActiveScene ().name);
}
}
it prints out "It turns out S11 PlayerBooking is not equal to S11 PlayerBooking"
Answer by bhayward_incrowd · Jan 25, 2016 at 04:40 PM
After having iterated through all characters in the two strings, I have found the answer! Unfortunately, my scene had a space in it; although, it wasn't a 'proper' space, as in unicode 32. In fact, it was unicode 160; a non-break space.
Note for the future: Don't use spaces!!
I would have suggested copying and pasting the string from the .unity asset to the class just to make sure they're the same.
I was having the same issue and this answer is what pointed me in the right direction. I used the String.Trim() to eli$$anonymous$$ate the wild symbols from beginning and end of the scene names.
Answer by OneCept-Games · Oct 26, 2017 at 08:39 AM
TIP: If it is not about whitespaces, then it might be that you have move your scene to another folder in the hierarchy. Build Settings seems to adapt this new folder, but you actually have to re-drag your scenes into the Build Settings, else you will have this error also. Just a tip if you happen to meet this issue again later when you are sure there are no spaces and spelling issue.
Yeah, my case was solved by dragging the scene again to build settings, I moved it to another folder and probably lost reference or something!
Thanks OneCept-Games, I encountered this issue after reorganising my projects folder structure.
Yup, just had exactly this issue.
Annoyingly, it turns out that the moved scenes will work perfectly fine in builds but won't be found correctly in the editor, which lead to a lot of confused frustration.
Definitely an editor bug.
I reorganised my folder structure and ran into this problem. I checked to see if the path names matched in File->BuildSettings and all were okay... So I took another route...
See, I actually have my scene names as an enum and then select which scene to load by setting the scene in the inspector and saying, for instance,
Scene$$anonymous$$anager.LoadSceneAsync(next_scene.ToString());
so now, ins$$anonymous$$d, I said
Scene$$anonymous$$anager.LoadSceneAsync( (int)next_scene);
This should also work just fine since my enum contains the scene names in th same order as the BuildSettings since the BuildSettings contain them in the order that I want them to be loaded... Turns out that with 3 scenes in BuildSettings, trying to call LoadSceneAsync with an int value of 1 still resulted in the scene not being present in build settings.
Does this constitute a bug, I wonder?
p.s. Forgot to mention... clearing BuildSettings and dragging the scenes in again fixed the numeric scene loading also
Answer by MADiFold · Jan 05, 2019 at 09:36 AM
Actually...(I just ran into it after getting my own Collaborated project from one system to another), it has to do with the fact that the project doesn't seem to like the items already in the list in the Buildscreen. Easiest is to remove all scenes and add them again. No need to change the code. The project will then be able to find the items again.
Answer by Dljcali82 · Feb 17, 2019 at 09:58 AM
One issue I've learned is that when you take the name as a string from another object.. if the object is a texture file (maybe others as well), it may associate that to the name. I learned this because I manually added the name of the file and it worked, yet when I try it with the string, the debug.log description has (UnityEngine.Texture2d) attached to the string output. Still trying to find the right solution for that, but I'm sure it won't be long before I do. Good luck!
Your answer

Follow this Question
Related Questions
After reloading the scene twice one script doesn't work. 0 Answers
SceneManager.LoadScene is crashing or freezing for Android Devices 3 Answers
Only half of work/wall spawping after die and restart game,Why load after die only half scene? 1 Answer
Get current scene number 3 Answers
Scene Editor Problem @username 0 Answers