Search Unity

[SOLVED] Load scene without being in build settings and without using AssetBundle

Discussion in 'Editor & General Support' started by bilalakil, Sep 16, 2019.

  1. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    77
    This is the closest I've gotten:

    Code (CSharp):
    1.     EditorSceneManager.OpenScene(
    2.         AssetDatabase.GUIDToAssetPath(
    3.             AssetDatabase.FindAssets(
    4.                 "t:SceneAsset " + MenuSceneName,
    5.                 new string[] { "Assets" }
    6.             )[0]
    7.         )
    8.     );
    However this generates an error at runtime:

    Code (CSharp):
    1. InvalidOperationException: This cannot be used during play mode, please use SceneManager.LoadScene()/SceneManager.LoadSceneAsync() instead.
    I can't follow its suggestion because those functions require the scene to be in build settings or an asset bundle. So, is there any other option?

    I wonder how (and if) Addressables achieve this? Note: I'm not willing to switch to Addressables - I'm quite enjoying working with AssetBundles.

    Why?

    My game uses AssetBundles for general loading of EVERYTHING, so there's only one blank scene in build settings. However, during development I'd rather not have to continuously build and load from AssetBundles, so I'm trying to dynamically load scenes WITHOUT having to add them to build settings.
     
    Last edited: Sep 16, 2019
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I'm curious why you don't want to just add the scenes to build settings. It only takes 2 seconds to enable/disable all your extra scenes in there (click the top of the list, hold shift, click the bottom of the list to select them all, then click on any check box and it will enable/disable all selected scenes).
     
  3. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    77
    "I would use coding and algorithms. - LaneFox" - I like it

    That's fine for a workaround, but doesn't really answer the question. It introduces user error, a smidge of extra cognitive load during the dev and build process (which I think we already have enough of), and would make it more difficult to package this solution and use it across multiple games.
     
    Last edited: Sep 16, 2019
  4. leyou-liyubin

    leyou-liyubin

    Joined:
    Sep 17, 2019
    Posts:
    1
    Use this method 'EditorSceneManager.LoadSceneAsyncInPlayMode' may solve your problem
     
  5. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    77
  6. Uelii

    Uelii

    Joined:
    Dec 12, 2022
    Posts:
    1
    Does this work in a builded version ?
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,674
    No class in the
    UnityEditor
    name space can be used in build.

    Please don't necro-post. If you have a new question, make a new post. It's FREE!!