Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Utility method for getting devices.

Discussion in 'AR/VR (XR) Discussion' started by Incode, Jan 30, 2020.

  1. Incode

    Incode

    Joined:
    Apr 5, 2015
    Posts:
    78
    Maybe I'm missing something, but it seems a little cumbersome that we have to get common devices via the GetDevicesWithCharacteristics or GetDevicesAtNodes. I imagine those new to XR have an even tougher time.

    Typically getting a single controller looks like:
    Code (CSharp):
    1.  
    2. var myLeftHandController = new UnityEngine.Xr.InputDevice();
    3. var leftHandedControllers = new List<UnityEngine.XR.InputDevice>();
    4.  
    5. var desiredCharacteristics = UnityEngine.XR.InputDeviceCharacteristics.HeldInHand | UnityEngine.XR.InputDeviceCharacteristics.Left | UnityEngine.XR.InputDeviceCharacteristics.Controller;
    6. UnityEngine.XR.InputDevices.GetDevicesWithCharacteristics(desiredCharacteristics, leftHandedControllers);
    7.  
    8. if(leftHandedControllers.Count > 0)
    9. {
    10.     myLeftHandController = leftHandedControllers[0];
    11.     Debug.Log(string.Format("Device name '{0}' has characteristics '{1}'", device.name, device.characteristics.ToString()));
    12. }
    I think 90% of the time what we really want is:
    Code (CSharp):
    1. var myLeftHandController = new UnityEngine.XR.InputDevice();
    2.  
    3. InputDevices.TryGetLeftHandController(out myLeftHandController);
    It seems like the common cases (e.g. headset, left controller, and right controller) for this could be implemented as utility methods in the InputDevices class.
     
  2. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    Thanks for the feedback. Well def think about it.
     
    Incode likes this.