Mixedrealitytoolkit-unity: SearchForAndEnableExistingPlayspace throws an exception

Created on 6 Sep 2019  路  2Comments  路  Source: microsoft/MixedRealityToolkit-Unity

Describe the bug

MixedRealityPlayspace automatically register to EditorSceneManager.sceneClosed.

I've my own editor 'play' overide (basically hooking the Play button, to launch a rootscene-with mixedrealitytoolkit and playspace), even if that rootscene is not currently active or loaded.
during that hook, i call UnityEditor.SceneManagement.EditorSceneManager:OpenScene
which will trigger the event EditorSceneManagerSceneClosed that is catched by MixedRealityPlayspace.

ArgumentException: The scene is not loaded.
UnityEngine.SceneManagement.Scene.GetRootGameObjects (System.Collections.Generic.List`1[T] rootGameObjects) (at C:/buildslave/unity/build/Runtime/Export/SceneManager/Scene.cs:91)
UnityEngine.SceneManagement.Scene.GetRootGameObjects () (at C:/buildslave/unity/build/Runtime/Export/SceneManager/Scene.cs:75)
Microsoft.MixedReality.Toolkit.Utilities.RuntimeSceneUtils+<GetRootGameObjectsInLoadedScenes>d__2.MoveNext () (at Assets/MixedRealityToolkit/Utilities/Scenes/RuntimeSceneUtils.cs:56)
Microsoft.MixedReality.Toolkit.MixedRealityPlayspace.SearchForAndEnableExistingPlayspace (System.Collections.Generic.IEnumerable`1[T] rootGameObjects) (at Assets/MixedRealityToolkit/Utilities/MixedRealityPlayspace.cs:274)
Microsoft.MixedReality.Toolkit.MixedRealityPlayspace.SceneManagerSceneUnloaded (UnityEngine.SceneManagement.Scene scene) (at Assets/MixedRealityToolkit/Utilities/MixedRealityPlayspace.cs:247)
UnityEngine.SceneManagement.SceneManager.Internal_SceneUnloaded (UnityEngine.SceneManagement.Scene scene) (at C:/buildslave/unity/build/Runtime/Export/SceneManager/SceneManager.cs:253)
UnityEditor.SceneManagement.EditorSceneManager:OpenScene(String, OpenSceneMode)

To reproduce

Steps to reproduce the behavior:
hopefully this is the minimal code that should help reproduce :

[InitializeOnLoad]
public static class PlayService
{
    static PlayService()
    {
        EditorApplication.playModeStateChanged += OnPlaymodeChanged;
    }
    private static void OnPlaymodeChanged(PlayModeStateChange state)
    {
        switch (state)
            {
            case PlayModeStateChange.ExitingEditMode:
            EditorSceneManager.OpenScene(SceneUtility.GetScenePathByBuildIndex(0), OpenSceneMode.Single);
            break;
            }
    }
}

then : click on Unity default Play Button.
when calling OpenScene, it will first unload all scenes, hence there are no scenes opened anymore, which leads to the exception when trying to get gameobjects.

(be sure to uncheck "clear on play" in the unity console, as the error will be cleared just before entering play mode)

Expected behavior

no exception

Your Setup (please complete the following information)

  • Unity Version [2018.4.2f1]
  • MRTK Version [v2.0.0]

Target Platform (please complete the following information)

  • HoloLens
0 - Backlog Bug Consider for Next Iteration Help Wanted Multi-Scene Thousand Cuts

Most helpful comment

potential fix:
add same 'hack' in RuntimeSceneUtils.GetRootGameObjectsInLoadedScenes that is in EditorSceneUtils

                if (!loadedScene.isLoaded)
                {   // Oh, Unity.
                    continue;
                }

note to myself: i should probably do some nice PRs

All 2 comments

potential fix:
add same 'hack' in RuntimeSceneUtils.GetRootGameObjectsInLoadedScenes that is in EditorSceneUtils

                if (!loadedScene.isLoaded)
                {   // Oh, Unity.
                    continue;
                }

note to myself: i should probably do some nice PRs

@gilbdev, if you feel good about sending out a PR, we can definitely review it and get it in (@Railboy because this is in some of the scene work that he did)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ritijain picture ritijain  路  3Comments

StephenHodgson picture StephenHodgson  路  3Comments

StephenHodgson picture StephenHodgson  路  3Comments

dustin2711 picture dustin2711  路  3Comments

brean picture brean  路  3Comments