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.
  2. Dismiss Notice

Bug new XR package creates huge CPU spikes every 5 seconds, report IN-23355

Discussion in '2022.2 Beta' started by creat327, Nov 17, 2022.

  1. creat327

    creat327

    Joined:
    Mar 19, 2009
    Posts:
    1,739
    When my game starts, i check whether there is an virtual device (oculus) connected to decide how my game should behave.

    This works just fine, the issue is that since the previous XR unity version, when you check for the device existance, Unity begins a loop every 5 seconds to check if it gets connected.



    This is a problem because it creates a huge CPU spike and your game begins jittering, every 5 seconds!



    Here is a simple code to check if XR is available:

    Code (CSharp):
    1. var xrDisplaySubsystems = new List<XRDisplaySubsystem>();
    2.  
    3. SubsystemManager.GetInstances<XRDisplaySubsystem>(xrDisplaySubsystems);
    4.  
    5. foreach (var xrDisplay in xrDisplaySubsystems)
    6.  
    7. {
    8.  
    9. if (xrDisplay.running)
    10.  
    11. {
    12.  
    13. return true;
    14.  
    15. }
    16.  
    17. }
    18.  
    19. return UnityEngine.XR.XRSettings.isDeviceActive;


    and then, from that moment, the editor will be throwing these errors every 5 seconds with a huge cpu spike:



    Please make sure the device is connected. Will try to restart xr periodically.

    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

    Failure to restart OpenXRLoader after shutdown.

    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)


    This began happening with the XR update from 2 weeks ago.

    Bug report: IN-23355
     
    Ony likes this.