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.
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!
[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?