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)
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)
no exception
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)
Most helpful comment
potential fix:
add same 'hack' in
RuntimeSceneUtils.GetRootGameObjectsInLoadedScenesthat is in EditorSceneUtilsnote to myself: i should probably do some nice PRs