Game Dev Cheat Sheet

Runtime exceptions

Scene 'X' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.

The exact message

Scene 'X' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
Variants of this message
  • couldn't be loaded because it has not been added to the build settings
  • 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...
  • Scene '' couldn't be loaded because it has not been added to the build settings
  • Scene 'Assets/Scenes/Level1.unity' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.

What it means

Unity could not resolve the name or path you passed to SceneManager.LoadScene against its list of scenes in the build. Only scenes ticked in the Build Settings window are compiled into the player and available at runtime, and the lookup is done against the path recorded when the scene was added, not against whatever is on disk now. The bracketed number in the message is the build index Unity found, and -1 means it found nothing at all.

Causes and fixes

Ranked by how often they actually occur, most common first.

  1. The scene was never added to the Build Settings list

    By far the most common case, and the one the error message is written for. A scene that exists in your Assets folder and opens fine in the Editor is still not part of the build until you add it. Play mode in the Editor is more forgiving than a build in some workflows, so this often surfaces the first time you test a scene transition.

    The fix: Open File > Build Settings (File > Build Profiles > Scene List in Unity 6 and later), then drag the scene from the Project window into the Scenes In Build list. The scene you want to start on must be at index 0.

    Source: Unity Scripting API: SceneManager.LoadScene

  2. The scene is in the list but its checkbox is unticked

    The Scenes In Build list shows every scene you have added, each with a checkbox. Unticking a scene leaves it visible in the list but excludes it from the build, and it is then not loadable at runtime. This reads as a paradox because the scene is plainly there on screen.

    The fix: Tick the checkbox next to the scene in the Scenes In Build list. Only ticked scenes are assigned a build index; unticked ones report -1.

    Confirm what the runtime can actually see, rather than trusting the Editor window.

    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class SceneListDump : MonoBehaviour
    {
        void Start()
        {
            Debug.Log($"Scenes in build: {SceneManager.sceneCountInBuildSettings}");
    
            for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++)
            {
                string path = SceneUtility.GetScenePathByBuildIndex(i);
                Debug.Log($"[{i}] {path}");
            }
    
            // -1 means the name or path resolved to nothing.
            Debug.Log($"Index of 'Level1': {SceneUtility.GetBuildIndexByScenePath("Level1")}");
        }
    }

    Source: Unity Discussions: scene IS added to build settings, error persists

  3. The string does not match the scene name or path

    LoadScene accepts either the scene name with no .unity extension, or the path exactly as shown in the Build Settings window, also without the extension. It does not accept a partial path, and it does not accept the name with the extension attached. Matching is case insensitive, except when the scene comes from an AssetBundle. A single wrong character, including a space in "Level 1" where the asset is called "Level1", produces this error.

    The fix: Pass either the bare scene name or the full path as the Build Settings window displays it. Where two scenes share a name in different folders, you must use the path, because the name form loads the first match in the list.

    All three forms below are valid; the fourth is not.

    using UnityEngine.SceneManagement;
    
    SceneManager.LoadScene("Level1");                       // name only
    SceneManager.LoadScene("Scenes/Level1");                // path as shown in Build Settings
    SceneManager.LoadScene(2);                              // build index
    
    SceneManager.LoadScene("Assets/Scenes/Level1.unity");   // fails: extension included
    
    // Safer than a bare string: fails loudly at the call site rather than
    // silently doing nothing.
    public void Load(string sceneName)
    {
        if (SceneUtility.GetBuildIndexByScenePath(sceneName) < 0)
        {
            Debug.LogError($"'{sceneName}' is not in the build settings.", this);
            return;
        }
    
        SceneManager.LoadScene(sceneName);
    }

    Source: Unity Scripting API: SceneManager.LoadScene, sceneName rules

  4. The scene was moved or renamed after it was added

    The Build Settings list stores each scene by asset path. Moving a scene into a different folder, or renaming it, leaves a stale entry pointing at a path that no longer exists. The window may still show the scene, so this is the second case that reads as a contradiction. Reorganising a Scenes folder partway through a project is the usual trigger.

    The fix: Remove the stale entries from Scenes In Build and drag the scenes back in from their new locations. Re-adding is required; the list does not follow asset moves.

    Source: Unity Discussions: moving scenes between folders requires re-adding them

  5. An empty or uninitialised string reached LoadScene

    The message quotes the name it was given, so an error reading Scene '' with nothing between the quotes means the string was empty. This usually comes from a serialised field that was never filled in the Inspector, or from a lookup that returned null and was concatenated into the call.

    The fix: Read the quoted name in the message. If it is empty, the bug is upstream of LoadScene: trace where the string comes from and check the Inspector field or lookup that produces it.

    Source: Unity Discussions: host receives Scene '' couldn't be loaded

  6. A custom build script does not set the scene list

    BuildPipeline.BuildPlayer takes its scenes from BuildPlayerOptions.scenes, not from the Build Settings window. A CI or automated build that leaves that array unset, or sets it from a stale list, produces a player whose scene list differs from what the Editor shows.

    The fix: Populate buildPlayerOptions.scenes explicitly, or derive it from EditorBuildSettings.scenes so the automated build and the Editor agree.

    Derive the list rather than hardcoding it, so the two cannot drift.

    using System.Linq;
    using UnityEditor;
    
    var buildPlayerOptions = new BuildPlayerOptions
    {
        scenes = EditorBuildSettings.scenes
            .Where(scene => scene.enabled)
            .Select(scene => scene.path)
            .ToArray(),
        locationPathName = "Builds/Game.exe",
        target = BuildTarget.StandaloneWindows64,
    };
    
    BuildPipeline.BuildPlayer(buildPlayerOptions);

    Source: Unity Discussions: custom build script must assign buildPlayerOptions.scenes

  7. An invisible character in the scene name

    Rare, and worth checking only once the causes above are ruled out. A scene name containing a non-breaking space (U+00A0) rather than an ordinary space looks identical in the Editor but does not match a string typed in code. Names pasted from a document or a chat window are the usual source.

    The fix: Rename the scene by typing the name fresh rather than pasting it, then re-add it to the Build Settings list. Comparing SceneUtility.GetScenePathByBuildIndex output against your literal in a diff tool will expose the mismatch.

    Source: Unity Discussions: scene name contained Unicode 160, a non-breaking space

How to prevent it

Do not pass scene names as bare string literals scattered through your code. Generate a constants class from the Build Settings list, or serialise a SceneAsset reference in the Inspector and read its name, so a rename or a typo becomes a compile error rather than a runtime one.

Add a guard at your single scene-loading entry point that checks SceneUtility.GetBuildIndexByScenePath before calling LoadScene. A logged error naming the offending scene is far quicker to diagnose than a transition that silently does nothing.

Re-check the Scenes In Build list after any reorganisation of your Scenes folder, and treat it as a file that needs reviewing in pull requests. EditorBuildSettings is serialised in ProjectSettings/EditorBuildSettings.asset, so changes to it show up in version control.

Unity version differences

The message text has been stable across Unity 2019 through Unity 6. In Unity 6 the scene list moved from File > Build Settings to File > Build Profiles, where it appears as the Scene List section, but the runtime behaviour and the error are unchanged.

Sources

Frequently asked questions

The scene is in my Build Settings list, so why do I still get this error?
Three things produce that contradiction. The scene's checkbox may be unticked, which leaves it in the list but out of the build. The scene may have been moved or renamed after it was added, leaving a stale path. Or the string you pass may not match the name or path exactly. Log SceneManager.sceneCountInBuildSettings and iterate SceneUtility.GetScenePathByBuildIndex to see what the runtime actually has, rather than trusting the window.
What does the -1 in the error message mean?
It is the build index Unity resolved for the name or path you gave it. Valid scenes have an index of 0 or higher matching their position in the Scenes In Build list. A value of -1 means the lookup failed entirely, so the name matched nothing rather than matching something that failed to load.
Do I need to add every scene to the Build Settings?
Every scene you intend to load with SceneManager.LoadScene, yes. Scenes loaded from an AssetBundle or through Addressables are the exception, because they are packaged separately and resolved by a different mechanism. Scenes used only during development can be left unticked to keep them out of the player.
Does the order of scenes in the Build Settings matter?
Yes, in one respect: the scene at index 0 is the one the player opens on. Beyond that the order only determines the build index each scene receives, which matters if you load scenes by index rather than by name. Loading by name is more robust because inserting a scene higher in the list renumbers everything below it.
Why does it work in the Editor but fail in a build?
Entering play mode from an already-open scene does not require that scene to be in the build list, so a scene you have been testing directly can appear to work. The first LoadScene call to it in a build is the point at which the list is consulted. Test scene transitions from your intended starting scene rather than from the scene you happen to be editing.

Last updated: