Hi my name is Dean and I am 12 years old and my brother Evan is 10 we are going through the class learning a lot about programming, but we have come across a problem. We have added all of the scenes into the build settings, (accidentally a couple times) and we put them in order, but the error states, “Level ‘’ (-1) couldn’t be loaded because it has not been added to the build settings.
To add a level to the build settings use the menu File->Build Settings…
LevelManager:LoadLevel(String) (at Assets/LevelManager.cs:8)
UnityEngine.EventSystems.EventSystem:Update()” We have tried to figure out how to fix this error, but to no avail we would like to have your help in finding our error. Thank you.
Hi @Dean_DiCarlo, welcome to you and your brother.
Often this error will be generated because the name of the scene you are trying to load doesn’t match the saved scene name.
In your specific case I see that the error states
Level '', those two quotes tell me that the parameter
name wasn’t passed in to the method call. Note your debug line above it, there is no name for the scene.
Hope this helps, if you can find the problem after this post your full script and I will be happy to help you both.
Thank you for your help, we were following along with the instructor, but we think that maybe it is just a very minor issue. Thank you for helping us. Here is a zip file of our assets. Thank you for all your help, we really appreciate you helping us.
Dean and Evan
Number Wizard UI.zip (14.5 KB)
Hi Dean and Evan,
Thanks for the zip file.
So, lets run through a little bit of debugging together as it is a useful skill.
Inside the zip file I see the following files;
Win, Lose, start and GameNew scenes
Now, from your error message in the screenshot above, we saw that the “name” of the scene was not being passed through to the
LoadLevel() method within your LevelManager. As there is only the one script file this is really easy to rule out, as there isn’t any other code in there which calls that method. Great!
So, what do we know, well, we know that in one of the four scenes there must be at least one thing calling your LevelManager to load a new level using the
The obvious place to start would be the scene named start.
You have a button in this scene to start a new game. In order for this to operate you would need to handle the click event of the button, which in turn would load the new scene. Lets start there!
- Select the start / new game button in your scene.
- In the Inspector, scroll down to the button script component
- Look under the On Click event, you will have most likely correctly dragged your LevelManager game object into this.
- You will have most likely selected the
LoadLevel()method from the drop down menu that appears.
- What you have most likely not done is specified the name of the scene that you want to load in the parameter field that appears next to it.
Note - the text you enter here will need to match, exactly, the name of your scene you wish to load, so enter
GameNew in this field.
As this is a fairly easy mistake to make, check any other buttons you have, including on the other scenes as well, as you will most likely have buttons to return you to the menu on the Lose and Win scenes.
I hope this solves the problem for you and is fairly straight forward to follow. If you need any further help, or if this doesn’t resolve your issue please let me know.
Thank you so much Rob! That was really awesome of you to help us. We got the script to work by adding in the name of the scene in the on click section. Thank you so much we got it all to work!
Thank you for your help!
Dean and Evan
Hi Dean and Evan,
You are both more than welcome.
Little hurdles like this arise from time to time and it can be a really useful exercise in debugging and working things through, hopefully the steps in my post will help you in the future also.
Looking forward to playing your game when you have completed it and are ready to share, if there is anything else, just post and someone from the community will help you out.