[SOLVED] OpenXR Editor lags when I take off Headset

Hi guys, I’ve been looking for a solution but I haven’t found it. I am desperate.

I’m developing a windows application with OpenXR: when I take off the Oculus a scene is loaded with a video. The problem is that both in the Editor and in the build there is a huge lag (even if the scene is empty) when the Oculus is not worn.

Run in background is checked.

I have enabled OculusXR Feature and this is the script that allows to recognize if the headset is worn or not:

using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.XR.OpenXR.Features;
#if UNITY_EDITOR
[UnityEditor.XR.OpenXR.Features.OpenXRFeature(UiName = "VR State Tracking",
    BuildTargetGroups = new[] { BuildTargetGroup.WSA, BuildTargetGroup.Standalone, BuildTargetGroup.Android },
    Company = "Your Company",
    Desc = "Tracks state changes.",
    Version = "0.0.1",
    FeatureId = featureId)]
#endif

public class MyOwnXRFeature : OpenXRFeature
{
    public const string featureId = "com.yourcompany.features.statetracking";


    // This is to change a number of state changes in a very granular way:
    protected override void OnSessionStateChange(int oldState, int newState)
    {
        Debug.Log($"OnSessionStateChange: {oldState} -> {newState}");
    }

    // This will happen when headset put on:
    protected override void OnSessionBegin(ulong xrSession)
    {
        Debug.Log($"Feature OnSessionBegin: {xrSession}");
        Debug.Log("Put on");

        SceneManager.LoadScene("Dashboard 2");
    }

    // This will happen when headset taken off:
    protected override void OnSessionEnd(ulong xrSession)
    {
        Debug.Log($"eatureOnSessionEnd: {xrSession}");
        Debug.Log("Put off");

        SceneManager.LoadScene("Videoloop");

    }
}

Is this lag an OpenXR problem?
Because with OVRManager I didn’t have this problem, but the HDMMounted/HDMUnmounted events didn’t work (they only worked in the editor). I can use OVRManager if you know a way to make it works in build.

I use:
Unity 2021.3.0f1
Quest 2 & Quest Pro

Thank you for your time, and sorry for my English!

If you have runInBackground checked, it shouldn’t be causing lag when the headset is removed. Could you submit a bug report using a simplified version of your project with this same functionality? Then link the report issue ID in this thread.

  1. Update Unity
  2. Update OpenXR to 1.6 (or 1.7)
  3. Update Oculus XR Plugin and/or Oculus Integration

That fixed it for me

Thanks for your answers, at the last I fixed my problem with OVRManager.
Long story short: With me HDMMounted/HDMUnmounted event works perfectly only with load a new scene.

For exemple in “Menu” scene, when user takes off headset:

void Start()
    {

        OVRManager.HMDUnmounted += HandleHMDUnmounted;

        void HandleHMDUnmounted()
        {
            SceneManager.LoadScene("screensaverScene");
        }

    }

In “screensaverScene”, when user puts on headset:

    void Start()
    {

        OVRManager.HMDMounted += HandleHMDMounted;

        void HandleHMDMounted()
        {
            SceneManager.LoadScene("Menu");
        }
    }

Maybe use application focus instead