What does this error message mean?
Hi, I am very new to Unity and C#. I am making a 2d platformer. This same error message comes up when the player hits a killzone: Scene 'Assets/First Level (1).unity' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded. To add a scene to the build settings use the menu File->Build Settings...
I have tried adding a scene to the build settings and have come up with no luck. Here is the code that I am using:
using System;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace UnityStandardAssets._2D
{
public class Restarter : MonoBehaviour
{
private void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "Player")
{
SceneManager.LoadScene(SceneManager.GetSceneAt(0).path);
}
}
}
}
Help would be appreciated.
If you are looking for a scene at a path then make sure the asset exists and the path is correct.
I am 100% sure the asset exists, I just don't know how to make the path correct.
Answer by Addyarb · May 04, 2016 at 04:51 AM
Hi there,
To fix your issue, please do the following.
Open your scene up Click File>Build Settings
Is your scene in that screen? If not, click "Add Open Scenes." (it's to the middle right of that window!).
Replace "SceneManager.GetSceneAt(0).path" with "SceneManager.LoadScene("your_scene_name_here").
To clarify, this error - in Layman's terms means:
You haven't added the scene, or we don't know the scene you're talking about. This could be due to a name error, a scene that is disabled in the Build Settings window (via an un-ticked scene), or simply not having the scene in the Build Settings at all.
Let me know in a comment below if this doesn't work for you - and I'll do my best to troubleshoot and help you!
I had the scene enabled and made sure of that. So, I changed the code, but when I added the scene name it showed an error message saying that it didn't exist in the context. It also said that it did not have a definition for path. Is there something that I am doing wrong? $$anonymous$$y scene name is Full_Game.
Try these steps:
Create (or rename the scene in question) a new scene called "Test" by right-clicking in the assets area and selecting Create>Scene.
Double-click on that scene
Go to File>Build Settings>Add Open Scenes
Replace the current code in your trigger function with:
Scene$$anonymous$$anager.LoadScene("Test");
Also, could you please post a screenshot of your Build Settings, as well as a screenshot/copy-paste of your code.
Good luck!
Looks like it worked. Thank you so much!
Answer by Angelo101 · Dec 31, 2017 at 05:03 AM
[HELP] I am currently having the same issue but I'm using the function SceneManager. GetSceneByIndex. Why won't the function SceneManager. GetSceneByBuildIndex() work. Doesn't that just search for the index in manager and find it that's what the description in the API says?
Your answer
Follow this Question
Related Questions
I Need help with scripting a first person camera? 1 Answer
File error on new project 1 Answer
Why am I still getting "IOException: The port 'COM1' does not exist"? 1 Answer
ArgumentNullException: Argument cannot be null. Parameter name: value 0 Answers
Can't Add Script "The script needs to derive from MonoBehaviour!" 1 Answer