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

This is the closest I’ve gotten:

    EditorSceneManager.OpenScene(
        AssetDatabase.GUIDToAssetPath(
            AssetDatabase.FindAssets(
                "t:SceneAsset " + MenuSceneName,
                new string[] { "Assets" }
            )[0]
        )
    );

However this generates an error at runtime:

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.

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).

“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.

1 Like

Use this method ‘EditorSceneManager.LoadSceneAsyncInPlayMode’ may solve your problem

9 Likes

Perfect, thanks @leyou-liyubin - that’s exactly what I needed!

Does this work in a builded version ?

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!!