Search Unity

Game with screen mode and VR mode

Discussion in 'AR/VR (XR) Discussion' started by Elchtest, Jul 27, 2016.

  1. Elchtest

    Elchtest

    Joined:
    Sep 25, 2015
    Posts:
    10
    Hi folks,

    for experimentation I added the SteamVR plugin into the latest Unity Beta 5.4.0F2. I got the camera to work and was able to look around with the HTC Vive.

    So far, so good. But I also want to be able to NOT use VR and to just play on the monitor. I tried disabling the steamVR camera and using my other camera instead, but it the up/down head movements are locked and it will always take the orientation from the Vive. It also always launches up SteamVR, even if I want to be in monitor mode only.

    Is there a good way to switch between these two modes, e.g. only monitor mode for one session and VR mode for another session?

    Thanks!
     
  2. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
  3. Elchtest

    Elchtest

    Joined:
    Sep 25, 2015
    Posts:
    10
    Thanks thep3000!

    I was able to manually set UnityEngine.VR.VRSettings.enabled = false in one of my scripts in the Awake() function.

    However, as long as the Vive is plugged in, it will still open up SteamVR (Console: "OpenVR initialized") and then close it again after I set it to false (Console: "OpenVR Shutdown").

    Is there a way to disable it even earlier so it doesn't have to initialize and shutdown again?

    Update: found the "Virtual Reality Supported" box in PlayerSettings, which does the job for now.
     
    Last edited: Jul 28, 2016
  4. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    You should leave Virtual Reality Supported checked, otherwise you will not be able to switch to VR mode at runtime.

    If you want OpenVR to not auto-start, you should add "None" to the VR SDKs list in the first position, with OpenVR in the next position. At startup, we will try to initialize each VR SDK in order. Since 'none' is first, we'll start in non-vr mode, and you will later be able to change the https://docs.unity3d.com/540/Documentation/ScriptReference/VR.VRSettings-loadedDeviceName.html to openvr, and then enable.
     
    Psyco92 likes this.
  5. Elchtest

    Elchtest

    Joined:
    Sep 25, 2015
    Posts:
    10
    Many thanks, thep3000!

    I put in the order of None first and OpenVR second. In the beginning, I load
    UnityEngine.VR.VRSettings.LoadDeviceByName("None") in case someone changed it in the previous run.

    With F5 I can now toggle VR on and off. I noticed it takes 2 frames before it seems to be correctly enabled.

    Code (CSharp):
    1.   private int frameNumberSwitched = -10;
    2.   private const int numberOfFramesToSwitchToVrInUnity = 2;
    3.   private bool currentlyVRenabled = false;
    4.  
    5.     void Update () {
    6.     if((Time.frameCount - frameNumberSwitched == numberOfFramesToSwitchToVrInUnity) && UnityEngine.VR.VRDevice.isPresent) {
    7.       UnityEngine.VR.VRSettings.enabled = true;
    8.       return;
    9.     }
    10.  
    11.     if((Time.frameCount - frameNumberSwitched == numberOfFramesToSwitchToVrInUnity) && !UnityEngine.VR.VRDevice.isPresent) {
    12.       UnityEngine.VR.VRSettings.LoadDeviceByName("None");
    13.       return;
    14.     }
    15.  
    16.     if(Input.GetKeyDown(KeyCode.F5)) {
    17.       if(!currentlyVRenabled) {
    18.         UnityEngine.VR.VRSettings.LoadDeviceByName("OpenVR");
    19.         currentlyVRenabled = true;
    20.       } else {
    21.         UnityEngine.VR.VRSettings.LoadDeviceByName("None");
    22.         currentlyVRenabled = false;
    23.       }
    24.  
    25.       frameNumberSwitched = Time.frameCount;
    26.     }
    27.     }
    Now one thing I noticed when switching back to None is, that the field of view is much too high.

    Question: How can I reset the rendering values like field of view when loading "None" to what it was before using "OpenVR"?

    Thanks!
     
  6. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    i doesn't have the method "UnityEngine.VR.VRSettings.LoadDeviceByName();"

    Unity 5.3.4f1
     
  7. Elchtest

    Elchtest

    Joined:
    Sep 25, 2015
    Posts:
    10
    @Neo-Gamefactory It might be that method is only available in Unity 5.4.0 and newer.
     
  8. Neo-Gamefactory

    Neo-Gamefactory

    Joined:
    Oct 18, 2012
    Posts:
    145
    yeah :D i saw it yesterday after the update xD

    thank you :)
     
  9. tapatsup781

    tapatsup781

    Joined:
    Apr 27, 2017
    Posts:
    2
    but what if i want to toggle the vr camera itself from like outside of a car and the inside of it?