Search Unity

  1. Get the latest news, tutorials and offers directly to your inbox with our newsletters. Sign up now.
    Dismiss Notice

[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:
    18
    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,084
    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:
    18
    "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
     
    krisz1017 and DevilAngelHeart like this.
  5. bilalakil

    bilalakil

    Joined:
    Jan 28, 2018
    Posts:
    18
unityunity