Search Unity

VR Issue with Toggling XR on and off

Discussion in 'AR/VR (XR) Discussion' started by Stanchion, Aug 21, 2019.

  1. Stanchion

    Stanchion

    Joined:
    Sep 30, 2014
    Posts:
    269
    I am trying to make it so you can switch between VR and NonVR mode at any time.
    I am testing with a simple script
    Code (CSharp):
    1. if (Input.GetKeyDown(KeyCode.O))
    2.         {
    3.             XRSettings.enabled = true;
    4.         }
    5.         else if (Input.GetKeyDown(KeyCode.P))
    6.         {
    7.             XRSettings.enabled = false;
    8.         }
    9. C
    However this causes stuttering for about 10 seconds upon switching back to VR.

    So far I have tested this with 2017.4 LTS, 2018.4 LTS, 2019.1.0f2, and 2019.21f1

    Trying to figure out if I am missing something.
     
  2. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    Given the code snippet you have here I can't tell much other than it looks like you aren't setting things up correctly code wise. You can't just set enabled true. You need to make sure you are reloading the correct device and waiting appropriately (at least one frame). You can see an example of how to use LoadDeviceByName here: https://docs.unity3d.com/ScriptReference/XR.XRSettings.LoadDeviceByName.html.

    When disabling XR you only need to set enabled to false and don't need to load anything (though still wait at least one frame).