Search Unity

InputDeviceRole vs XRNode for getting hand devices

Discussion in 'AR/VR (XR) Discussion' started by Brad-Newman, May 28, 2019.

  1. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    185
    Is there any difference between the following methods for getting a hand device? Or do they return the same device result all the time?

    Code (CSharp):
    1. List<InputDevice> leftHandDevices = new List<InputDevice>();
    2. UnityEngine.XR.InputDevices.GetDevicesWithRole(UnityEngine.XR.InputDeviceRole.LeftHanded, leftHandDevices);
    3.  
    Code (CSharp):
    1. List<InputDevice> leftHandDevices = new List<InputDevice>();
    2. UnityEngine.XR.InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, leftHandDevices);
    If they are identical, it seems confusing to have two methods; and XRNode.LeftHand, XRNode.RightHand should be removed?
     
  2. joepl

    joepl

    Unity Technologies

    Joined:
    Jul 6, 2017
    Posts:
    87
    Hey Brad,

    Both API's will currently return devices at the same endpoint. The `GetDevicesWithRole` API is the more current one. XRNode is a part of the old XR tracking API and will get deprecated soon. `UnityEngine.XR.InputDeviceRole` is part of the more current Unity XR InputDevices API and should be the preferred one.

    Hope that helps.
     
  3. Brad-Newman

    Brad-Newman

    Joined:
    Feb 7, 2013
    Posts:
    185
    Ah, makes sense. Thanks for clarifying!
     
  4. c_Feng

    c_Feng

    Joined:
    May 15, 2017
    Posts:
    18
    I just attempted implementing device tracking in Unity 2019.4 using the XRNode API and the XRNodeState class. I was confused that it wasn't working. The documentation doesn't state anything about the XRNode system being deprecated save some of the older methods. Can the documentation at least be updated so that developers know to use the InputDevices API instead?
     
    ROBYER1 likes this.
  5. ROBYER1

    ROBYER1

    Joined:
    Oct 9, 2015
    Posts:
    1,454
    This pissed me off to no extent, started writing a simple test using the documentation and wondered why it wasn't working.
     
  6. EntertainmentEnterprise

    EntertainmentEnterprise

    Joined:
    Aug 22, 2018
    Posts:
    18
    The person who answered is wrong from what I can tell... when I try to use the method they said is going to remain after the other is deprecated, Unity actually tells me that that is going to be deprecated and doesn't give me that warning on the XRNode method. I think they got them mixed up. Makes sense, because the XRNode is much newer from what I can tell, and that is the way they are trying to go with everything else.

    Edit: I was wrong. Both are obsolete. Use Characteristics instead of Roles or Nodes. Example in unity docs for XR Input.
     
    Last edited: Sep 22, 2020
  7. EntertainmentEnterprise

    EntertainmentEnterprise

    Joined:
    Aug 22, 2018
    Posts:
    18
    How would I then use GetLocalPosition() on the device in the list with this method?