Search Unity

Question Is there a way to know if a VR device is connected ?

Discussion in 'VR' started by LJ3N, Jul 4, 2021.

  1. LJ3N

    LJ3N

    Joined:
    May 8, 2020
    Posts:
    5
    Hello,

    I am currently working on an application using OpenXR. I wanted to be able to start the appliation in desktop mode when no VR device is found. I tried to achieve that using UnityEngine.XR.InputDevices.

    Code (CSharp):
    1.  
    2.         var inputDevices = new List<UnityEngine.XR.InputDevice>();
    3.         UnityEngine.XR.InputDevices.GetDevices(inputDevices);
    4.         Debug.Log(inputDevices.Count);
    5.  
    6.  
    7.         foreach (var device in inputDevices)
    8.         {
    9.            Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", device.name, device.characteristics.ToString()));
    10.         }
    11.  
    Problem is that when I start the application in the Editor whith my HP Reverb G2 connected it starts correctly using the headset but my list of input device is empty. Did I miss something or is there a simpler way to do that ?
     
  2. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467
  3. danjirovec

    danjirovec

    Joined:
    Apr 28, 2020
    Posts:
    6
    Hey, just checking if you resolved this issue? I'm currently having the same problem
     
  4. joejo

    joejo

    Unity Technologies

    Joined:
    May 26, 2016
    Posts:
    958
    The post from @the_real_apoxol is the way to do this. There is no way to know if a device is connected without starting XR in some way and seeing if it succeeds or not.
     
  5. danjirovec

    danjirovec

    Joined:
    Apr 28, 2020
    Posts:
    6
    Is there an easy way to get a list of devices just in the Editor? For some reason HP Reverb G2 works fine but I can't manage to listen to button pressing because the device list is always empty
     
  6. the_real_apoxol

    the_real_apoxol

    Unity Technologies

    Joined:
    Dec 18, 2020
    Posts:
    467