Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question [SOLVED] OpenXR Editor lags when I take off Headset

Discussion in 'VR' started by unity_keywe, Mar 29, 2023.

  1. unity_keywe

    unity_keywe

    Joined:
    Dec 9, 2019
    Posts:
    2
    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:

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEngine.SceneManagement;
    4. using UnityEngine.XR.OpenXR.Features;
    5. #if UNITY_EDITOR
    6. [UnityEditor.XR.OpenXR.Features.OpenXRFeature(UiName = "VR State Tracking",
    7.     BuildTargetGroups = new[] { BuildTargetGroup.WSA, BuildTargetGroup.Standalone, BuildTargetGroup.Android },
    8.     Company = "Your Company",
    9.     Desc = "Tracks state changes.",
    10.     Version = "0.0.1",
    11.     FeatureId = featureId)]
    12. #endif
    13.  
    14. public class MyOwnXRFeature : OpenXRFeature
    15. {
    16.     public const string featureId = "com.yourcompany.features.statetracking";
    17.  
    18.  
    19.     // This is to change a number of state changes in a very granular way:
    20.     protected override void OnSessionStateChange(int oldState, int newState)
    21.     {
    22.         Debug.Log($"OnSessionStateChange: {oldState} -> {newState}");
    23.     }
    24.  
    25.     // This will happen when headset put on:
    26.     protected override void OnSessionBegin(ulong xrSession)
    27.     {
    28.         Debug.Log($"Feature OnSessionBegin: {xrSession}");
    29.         Debug.Log("Put on");
    30.  
    31.         SceneManager.LoadScene("Dashboard 2");
    32.     }
    33.  
    34.     // This will happen when headset taken off:
    35.     protected override void OnSessionEnd(ulong xrSession)
    36.     {
    37.         Debug.Log($"eatureOnSessionEnd: {xrSession}");
    38.         Debug.Log("Put off");
    39.  
    40.         SceneManager.LoadScene("Videoloop");
    41.  
    42.     }
    43. }

    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!
     
  2. EdBlais

    EdBlais

    Unity Technologies

    Joined:
    Nov 18, 2013
    Posts:
    300
    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.
     
  3. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,448
    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
     
  4. unity_keywe

    unity_keywe

    Joined:
    Dec 9, 2019
    Posts:
    2
    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:
    Code (CSharp):
    1. void Start()
    2.     {
    3.  
    4.         OVRManager.HMDUnmounted += HandleHMDUnmounted;
    5.  
    6.         void HandleHMDUnmounted()
    7.         {
    8.             SceneManager.LoadScene("screensaverScene");
    9.         }
    10.  
    11.     }
    In "screensaverScene", when user puts on headset:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.  
    4.         OVRManager.HMDMounted += HandleHMDMounted;
    5.  
    6.         void HandleHMDMounted()
    7.         {
    8.             SceneManager.LoadScene("Menu");
    9.         }
    10.     }
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    3,448
    Maybe use application focus instead