Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Scene couldn't be loaded because it has not been added to the build settings

Discussion in 'Editor & General Support' started by kurifodo, Feb 16, 2023.

  1. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    I'm attempting to load a scene by name, and I'm encountering the following error.

    Scene 'Splash Screen [Title]' 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...
    UnityEngine.SceneManagement.SceneManager:LoadScene (string)
    Mayhem.Scenes.SceneTransitionManager/<>c__DisplayClass7_0:<TriggerFadeOut>b__0 () (at Assets/Scripts/Scenes/SceneTransitionManager.cs:120)
    Mayhem.Utilities.CoroutineCatalog/<FadeTo>d__1:MoveNext () (at Assets/Scripts/Utilities/CoroutineCatalog.cs:68)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)



    Please note,
    The error only occurs in the Unity editor. If I build my game and run the exe, scene loading works fine.


    The code I'm using to load the scene is as follows.

    SceneManager.LoadScene( "Splash Screen [Title]" );


    I have ensured that my Build Settings contains my scenes and they're enabled:

    upload_2023-2-16_1-39-55.png


    Here's the Build Settings file for confirmation:

    %YAML 1.1
    %TAG !u! tag:unity3d.com,2011:
    --- !u!1045 &1
    EditorBuildSettings:
    m_ObjectHideFlags: 0
    serializedVersion: 2
    m_Scenes:
    - enabled: 1
    path: Assets/Scenes/Startup.unity
    guid: bf6fa123cb7065e45abc7c16cce84e46
    - enabled: 1
    path: Assets/Scenes/Splash Screen [Game Studio].unity
    guid: 2cda990e2423bbf4892e6590ba056729
    - enabled: 1
    path: Assets/Scenes/Splash Screen [Title].unity
    guid: 785cdff26630c494792e2e1883dca63b
    - enabled: 1
    path: Assets/Scenes/Main Menu.unity
    guid: ff3652e75bd21b441871a43f530979e6
    - enabled: 1
    path: Assets/Scenes/Loudout [Single Player].unity
    guid: e610929b3842456419a7e60e4de42b13
    - enabled: 1
    path: Assets/Scenes/Gameplay.unity
    guid: f727863019d30d54ca16c181d8cfdc84
    m_configObjects: {}



    In addition to checking above, I'm logging all enabled scenes from `EditorBuildSettings.scenes` at runtime.

    Code
    Debug.Log( $"Enabled Build Settings Scenes: {string.Join( ", ", EditorBuildSettings.scenes.Where( s => s.enabled ).Select( s => s.path ) )}" );

    Runtime Logs
    Enabled Build Settings Scenes: Assets/Scenes/Startup.unity, Assets/Scenes/Splash Screen [Game Studio].unity, Assets/Scenes/Splash Screen [Title].unity, Assets/Scenes/Main Menu.unity, Assets/Scenes/Loudout [Single Player].unity, Assets/Scenes/Gameplay.unity


    Another check I'm performing is logging SceneManager state at runtime.

    Code
    Debug.Log( $"SceneManager.sceneCountInBuildSettings: {SceneManager.sceneCountInBuildSettings}" );

    string[] sceneNames = new string[SceneManager.sceneCountInBuildSettings];
    for ( int i = 0; i < SceneManager.sceneCountInBuildSettings; i++ )
    {
    sceneNames = SceneUtility.GetScenePathByBuildIndex( i );
    }
    Debug.Log( $"Scene Manager's Scene Names: {string.Join( ", ", sceneNames )}" );



    Runtime Logs
    SceneManager.sceneCountInBuildSettings: 0
    Scene Manager's Scene Names:



    I thought it odd that scene manager has zero scene count in from build settings given the other checks performed above, which show multiple scenes enabled.


    What have a tried so far in order to fix my problem?
    1. Restarted Unity
    2. Removed all scenes from Build Settings, saved, then added them back, saved
    3. Removed all spaces from scene names
    4. Upgraded Unity to latest LTS version (2021.3.18f1)
    5. Combinations of all of the above
    None of the above worked. I'm at a loss for what to do next. Let me know if more details are needed.
     
    Last edited: Feb 16, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    That's weird... try removing those [ and ] signs from the scene name. Anytime you use an identifier containing characters outside of A-Z and 0-9 you can have issues with random bits of code that fail to handle it.
     
  3. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    Thanks for the suggestion. However, it did not work.


    I changed the scene names to single letters as follows:

    upload_2023-2-16_10-24-17.png


    Same error, but with the letter name instead now.

    Scene 'B' 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...
    UnityEngine.SceneManagement.SceneManager:LoadScene (string)
    Mayhem.Scenes.SceneTransitionManager:TransitionToNextScene (Mayhem.Utilities.Events.SceneTransitionEventData) (at Assets/Scripts/Scenes/SceneTransitionManager.cs:77)
    UnityEngine.Events.UnityEvent`1<Mayhem.Utilities.Events.SceneTransitionEventData>:Invoke (Mayhem.Utilities.Events.SceneTransitionEventData)
    Mayhem.Utilities.Events.GameEventListeners.GameEventListener`3<Mayhem.Utilities.Events.SceneTransitionEventData, Mayhem.Utilities.Events.GameEvents.SceneTransitionEvent, Mayhem.Utilities.Events.UnityEvents.SceneTransitionUnityEvent>:OnEventRaised (Mayhem.Utilities.Events.SceneTransitionEventData) (at Assets/Scripts/Utilities/Events/GameEventListeners/GameEventListener.cs:89)
    Mayhem.Utilities.Events.GameEvents.GameEvent`1<Mayhem.Utilities.Events.SceneTransitionEventData>:Raise (Mayhem.Utilities.Events.SceneTransitionEventData) (at Assets/Scripts/Utilities/Events/GameEvents/GameEvent.cs:27)
    Mayhem.Utilities.GameScene:TransitionTo (string,single,single) (at Assets/Scripts/Utilities/GameScene.cs:95)
    Mayhem.Scenes.Startup.StartupScreen:Update () (at Assets/Scripts/Scenes/Startup/StartupScreen.cs:31)
     
  4. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    I confirmed this is strange behavior by using a different project and logging the scene manager state. The above code resulted in matching count and scene names as what Build Settings.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Yes, very odd. Even if I remove ALL scenes from my EditorBuildSettings, SceneUtility still reports one (1) scene, the scene I have open, either without any name if it is unsaved, or with the name it is saved with.

    First place I would look is that Mayhem.Scenes / Mayhem.Utilities class because we know this stuff DOES work, so follow the data back up the line.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    I did see one crazy engine a few years back that had this "scene manager" subsystem and they basically used ALL the same names as SceneManagement does, but repurposed it to their own internal list of scenes, which ended up having this exact behaviour:

    - I would add scene X to the Unity editor build settings
    - I would try to load Scene X
    - their code would say "Nope, don't have it" even though Unity does.
     
  7. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    I created a new Unity project, imported all my project files except for all of the scenes and build settings file from source control, recreated the scenes from scratch in the new project, added them to build settings and it works as expected. No code changes in my project.

    Huge sigh Unity.
     
  8. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    I ran into this issue again today, and I'm not sure what's causing it to repro. Do Unity devs follow these forums, or do I need to take this elsewhere to get eyes/help?

    The issue is causing me to lose a lot of development time when it occurs. This is only the second time, but based on how soon it came back after working around it, I'm sure it'll come back again if I recreate all my scenes manually again.
     
  9. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    Does nuking the Library folder do anything? I've had some weird build problems that went away after reimporting everything.
     
  10. MakeItRa1n

    MakeItRa1n

    Joined:
    Aug 12, 2023
    Posts:
    1
    Yo I had a problem where the namem of the level did not match the referencing name.

    My scene was called Level1 and i was calling Level 1.
    changed that then reloaded and it worked.
     
  11. justinmoeck85

    justinmoeck85

    Joined:
    Apr 3, 2022
    Posts:
    2
    hey i have the same problem but what you did didint work by myself
     
  12. determi_love

    determi_love

    Joined:
    Jan 4, 2021
    Posts:
    7
    metoo ...

    Unity 2022.3.6f1
    Scene 'TeachMission' couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
     
  13. downstroypvp

    downstroypvp

    Joined:
    May 30, 2016
    Posts:
    40
    I have the exact opposite problem. When ran in editor, scene is found. But when I build I get the

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

    I have checked that the scene have the right name.

    I am on Unity 2022.3.13f1.
     
  14. ItsPopfight

    ItsPopfight

    Joined:
    Feb 12, 2024
    Posts:
    4
    This is pretty late but I found the solution by a YouTube tutorial. Go to files > Build Settings, then drag the scene into the "Scenes in build" tab. This is the tutorial I found