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

Question Getting XR Controller names via Input System?

Discussion in 'VR' started by NemesisWarlock, Nov 24, 2021.

  1. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    So I've started using OpenXR as our Backend, since apparently it's *nearly* production Ready.

    I've however, run into a roadblock. How do we get the name of the controller in use?

    I know that Unity can see these names, as they show up in the Input Debugger. How can I get those connected devices?



    upload_2021-11-24_23-57-36.png
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,969
    Code (CSharp):
    1.   void OnEnable()
    2.         {
    3.             InputDevices.deviceConnected += DeviceConnected;
    4.             List<InputDevice> devices = new List<InputDevice>();
    5.             InputDevices.GetDevices(devices);
    6.             foreach(var device in devices)
    7.                 DeviceConnected(device);
    8.         }
    9.         void OnDisable()
    10.         {
    11.             InputDevices.deviceConnected -= DeviceConnected;
    12.         }
    13.         void DeviceConnected(InputDevice device)
    14.         {
    15.             // The Left Hand
    16.             if ((device.characteristics & InputDeviceCharacteristics.Left) != 0)
    17.             {
    18.                 //Use device.name here to identify the current Left Handed Device
    19.             }
    20.             // The Right hand
    21.             else if ((device.characteristics & InputDeviceCharacteristics.Right) != 0)
    22.             {
    23.                 //Use device.Name here to identify the current Right Handed Device
    24.             }
    25.         }
    Got this from: https://forum.unity.com/threads/ope...ible-to-get-descriptive-device-names.1051493/
     
  3. NemesisWarlock

    NemesisWarlock

    Joined:
    Jan 21, 2017
    Posts:
    140
    Thanks! Had to do a bit of work to have this update on scene load as well as on device connection, but it all works now. :)
     
    DevDunk likes this.