Search Unity

Best way to track a (Vive) Tracker with the (native) XR classes?

Discussion in 'VR' started by R1PFake, Dec 8, 2018.

  1. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    216
    I want to track the position of a (Vive) Tracker with the native Unity XR classes.
    The InputTracking.GetLocalPosition method, doesn't work in this case, because there can be multiple tracker: https://docs.unity3d.com/ScriptReference/XR.InputTracking.GetLocalPosition.html

    It outputs a warning/error, https://docs.unity3d.com/ScriptReference/XR.InputTracking.GetNodeStates.html should be used instead.

    This method works, it returns a list of all states and there is also a entry for the "HardwareTracker" which gives the correct values for the connected Vive Tracker.

    But my question is: Is there a better way to handle this? Because I have to update the position every Update and it feels kinda weird to iterate the list every frame to get the "HardwareTracker" state from the updated list.

    I tried to store the reference of the "HardwareTracker" state, but they are structs so it's not possible.

    The state also has some (hardware) id property but I couldn't find any way to use this id to get the tracking information. The only methods I found are the two linked above.

    I don't want to use the SteamVR plugin, I know that it would be easier to handle tracker that way, I'm only asking about the native Unity XR.
     
    Last edited: Dec 8, 2018
  2. rahleenos

    rahleenos

    Joined:
    May 1, 2014
    Posts:
    2
    Did you ever get this working. I'm having the same problem.
     
  3. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    216
    I didn't find a better solution, so I used the "dirty" method to get all nodes every update and iterate the returned list to update all "HardwareTracker".

    Im not sure if the newer Unity versions have new methods to handle this in a "cleaner" way, because I don't work on the project anymore.

    I think the "easiest" way to deal with the (Vive-)Tracker is to use the SteamVR plugin.
     
    Last edited: Mar 17, 2019
  4. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    60
    Starting in 2019.1, there is a new set of InputDevices APIs

    This would allow you to search devices by role, and then you can get the CommonUsages.DevicePosition and CommonUsages.DeviceRotation features every frame. It reduces the iteration of nodes, and let's you cache and keep. Be sure to check InputDevice.isValid before using each frame in case it disconnects.

    And in 2019.2 we will be adding InputDevices.OnDeviceConnected, and InputDevices.OnDeviceDisconnected APIs so you can listen for new devices instead of searching for new devices as well.
     
    R1PFake likes this.
  5. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    216
    Looks good. I also like the new TryGetFeatureValue methods! I didn't try them yet, but it looks like we can call these methods to get the controller inputs instead of setting up input mappings and string names. Also haptics, awesome :)

    Im not sure if you are allowed to talk about this yet, but will these APIs also work for the Oculus Quest, which will be releases "soon"?
     
  6. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    60
    I can say that all XR devices that have native Unity support will work through these APIs, and we will be diligent in making sure the usages continue to make cross platform easier.

    And yes, no more string mappings, no more remembering that the left trigger is 9, and the right is 10, and scripts can be dragged and dropped in without requiring project setting changes in order to access XR inputs.
     
    R1PFake likes this.
  7. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    216
    I know this is a "old" thread, but I wanted to ask here instead of making a new one. Today is the official release of the Oculus Quest, I think all NDAs etc should be gone. So I wanted to ask which version of Unity I need for the Quest to use the above API. Does any of the current Unity versions have native support for the Quest?
     
  8. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    60
    Good News!
    You can develop for the quest with Unity 2017.4 and onwards!
     
    R1PFake likes this.