Eye tracking demo does not work due to bug in Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking.LoadAdditiveScene
Overview
When you try to click one of the four options in mrtk_eyes_00_RootScene nothing happens
Expected Behavior
When you try to click one of the four options in mrtk_eyes_00_RootScene you get one of the four test scenes
Actual Behavior
Console shows: ArgumentException: Scene to unload is invalid UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync (System.String sceneName)
Steps to reproduce
- Double click mrtk_eyes_00_RootScene to open
- Start Play mode
- Click any of the four options
Unity Editor Version
2018.3.11.f1
Mixed Reality Toolkit Release Version
2.0 RC1+, pulled from MRTK_development of April 10
Analysis
The code in method LoadNewScene of Microsoft.MixedReality.Toolkit.Examples.Demos.EyeTracking.LoadAdditiveScene contains a bug. It unloads an addivite scene whether one is loaded or not.
Solution
More statements need to be moved into the if statement and the check for empty scene name can go. Correct code should be:
private IEnumerator LoadNewScene(string sceneName)
{
AudioFeedbackPlayer.Instance.PlaySound(audio_OnSelect);
// Let's find out the name of the currently loaded additive scene to unload
if (SceneManager.sceneCount > 1))
{
lastSceneLoaded = SceneManager.GetSceneAt(1).name;
Debug.Log($"Last scene name: {lastSceneLoaded}");
// Let's wait in case we don't want to switch scenes too abruptly
yield return new WaitForSeconds(waitTimeInSecBeforeLoading);
SceneManager.UnloadSceneAsync(lastSceneLoaded);
}
Debug.Log($"New scene name: {SceneToBeLoaded}");
lastSceneLoaded = SceneToBeLoaded;
SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
}
This might have been addressed by @sostel's change (which was checked in one day after this was filed):
https://github.com/Microsoft/MixedRealityToolkit-Unity/pull/3870
By default, the root scene should automatically load a scene. This assumption was wrong though, as the script loading the additive scene got disabled by accident. The fix that I had submitted fixes that. However, I guess it's still a good idea to get the LoadNewScene script fixed, so that even if there's no scene automatically loaded, you can still use the scene menu. I'll look into it. Thanks!
You are welcome ;)