Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Detailed XR InputDevice names?

Discussion in 'AR/VR (XR) Discussion' started by justdizzy, Aug 2, 2019.

  1. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    61
    In Unity 2019.x, if I only have the OpenVR and Oculus packages via Package Manager (no SteamVR or Oculus integrations from Asset Store), is there a way to differentiate what input device (Vive Wand, Oculus Touch, whatever Knuckles are called now) the player is using with just UnityEngine.XR methods? XR.InputDevices seems to only return generic names.
     
  2. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    61
    I guess the answer is Input.GetJoystickNames() does provide detailed names, but for some reason my calls to it were returning empty strings till a second in.
     
  3. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    145
    In 2019.1 and onwards we are migrating to a new set of hopefully easier to use APIs for XR inputs.
    See: https://forum.unity.com/threads/any-example-of-the-new-2019-1-xr-input-system.629824/

    If you move to those APIs, then you have this handy property:
    https://docs.unity3d.com/ScriptReference/XR.InputDevice-name.html
    And in 2019.3 you will also get:
    https://docs.unity3d.com/2019.3/Documentation/ScriptReference/XR.InputDevice-serialNumber.html
    and
    https://docs.unity3d.com/2019.3/Documentation/ScriptReference/XR.InputDevice-manufacturer.html
    as well.

    The name property should correspond with GetJoystickNames, but I think this new API will help you more easily look for a specific device, as well as get names for things like HMDs.
     
  4. justdizzy

    justdizzy

    Joined:
    Mar 8, 2016
    Posts:
    61
    Aha! I tried XRDevices.getDevices() but it was returning a single empty item. When I added it to the XRInputTests GetJoystickNames test scene which calls the display method, ShowJoystickNames(), every 3 seconds, I found that it was working, but just not on the first call from Start(). Sounds like when I tested the very first time (which caused me to start this post) I was running into a race condition between the headset/controllers loading and the data becoming readable.

    On further testing, I also found:
    XRDevice.deviceLoaded never got called, which I set in Start(), maybe I should try it in OnEnable() instead.
    I added a test of XRDevice.isPresent to the beginning of ShowJoystickNames(), and it always returned true, even the first time when getDevices() returned empty objects.
    In Start(), if I check XRSettings.loadedDeviceName before calling ShowJoystickNames(), getDevices() returned the devices correctly on the first call.

    Sounds like some user error on my part, but maybe also a bug in the software. Also, this was only tested in editor, not on a built application.
     
  5. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    145
    I bet it's a dirty timing thing.

    So Start is called *right* before the first frame's Update call, and depending on the SDK we can be in a bit of a tricky situation in VR.

    Due to tracking, VR inputs are heavily tied to the rendering cycle. We often poll for inputs for both rendering AND the next frame before rendering the previous frame. This is to make sure that the tracking data we have for rendering the scene is as current as possible. The most obvious example of that is OpenVR, where we are actually polling our tracking data inside the graphics loop.

    What can happen is that we load the xrDevice before the first frame (and so before that frame's Start or OnEnable calls), and so your XRDevice.deviceLoaded call has already been sent, and so you won't see a new one. This is also why XRDevice.isPresent is true.
    But because we've not actually rendered out a frame, all we know is that devices exist and the SDK is polling. We don't yet know the names of those devices.

    This however looks very strange, and looks like a bug in the software:
    And I think I missed this the first time (and feel a little bad for suggesting you use InputDevices after you said it didn't suffice):
    Can you clarify?
    Testing in the office, we should be reporting names such as:
    `OpenVR Controller(VIVE Tracker Pro PVT)`
    `OpenVR Controller(Knuckles EV3.0 Left) - Left`
    `VIVE Tracker Pro PVT S/N LHR-OBDAA26C`
    `Oculus Touch Controller`
    etc...

    Can you give an example of a device name that is generic and the SDK it's reported from? I can make sure we provide as much detail as the SDK lets us.
     
  6. ixikos

    ixikos

    Joined:
    Jun 21, 2013
    Posts:
    21
    Could we possibly get a list of the current names of the devices? We are doing some custom controllers and variable setting and this seems like the best way to determine whats going on.
     
    andyman404 likes this.
  7. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    620
    @StayTalm_Unity with Unity 2019.3.3 and latest Oculus (v14), I'm currently getting:

    Oculus Quest / Link:
    InputDevice.name = "Oculus Rift S" (!)
    InputDevice.manufacturer = (NULL)
    InputDevice.serialNumber = "__SerialNumber__"
     
unityunity