Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

XR Inputs problems

Discussion in 'AR/VR (XR) Discussion' started by Mauro1965, Feb 26, 2020.

  1. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    I started using the new XR interface and now i'm facing issues never seen before.
    The interface behave correctly only if all controllers are connected in the moment unity starts and are always connected.
    In general (in particular under development) InputDevices.GetDevices,InputDevices.GetDevicesAtXRNode .. collect the same controller as different every time i need to reconnect them. So after some houres I have 2,4,6..10 controllers in the list and only two of them really works. All the controllers in the list appears as valid and active and actually i don't know how to select the right ones or reset this wrong list.

    Not only my C# code fails but even the "tracked pose driver" fails.

    Actually i'm testing with the Windows XR plugin.

    Is there a way to reset the XR system or filter the wrong inputdevices in a decent way?
     
  2. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    That is very definitely a bug, and should not be occurring.
    Can you report it with a basic Repro?
    I'm curious what version of Unity, what version of Windows XR, and the script you use to get devices.
     
  3. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    I'm usign Unity version 2019.3.0f3.
    XR Management ; 3.06
    XR Legacy Input Helpers: 1.3.11
    Windows XR plugin : 2.0.3
    In the project Settings->Player i see a warning "Legacy XR is currently disabled, Unity has detected yuo have more XR SDK packages installed", but i think this is normal on my XR configuration
    Testing in windows with an asus hmd headset and controllers

    First case (Empty project with only two cubes and without adding any C# code) :
    I simply add to my camera a Tracked pose Driver as Generic XR Device- Center Eye - HMD Reference.
    Then I created two simple cubes and added The Tracked pose Driver as Generic XR Controller -Left/Right Controller.

    If I restart Unity all works as aspected always, instead after few times if the controllers need to be riconnected one or all two cubes stop following the controller position. (I mean if I restart only using the play button on the editor)

    Second case:
    If I try to handle the data on the controllers i see that XR system (not always but often) every time a controller reconnects a new devices appears. The code is simply the one suggested in the scripting manual..
    Below my last one version trying to follow the last device instead the first one, but the working one seems to be absolutely random.

    public class XR_Test : MonoBehaviour
    {
    private InputDevice LeftController =new InputDevice();
    private InputDevice RightController = new InputDevice();
    private List<InputDevice> Devices = new List<InputDevice>();

    private Vector3 RightHandPos;
    private float RightHandTrigger;

    private Vector3 LeftHandPos;
    private float LeftHandTrigger;

    private Vector3 EyePos;
    private Quaternion EyeRotation;


    void trackingLost()
    {
    Debug.Log("********************* TrackingLost **************************");
    }

    // Start is called before the first frame update
    void Start()
    {
    InputDevices.GetDevices(Devices);
    foreach (var dev in Devices)
    {
    Debug.Log(string.Format("Device found with name '{0}' and role '{1}'", dev.name, dev.isValid.ToString()));
    }

    Debug.Log("----------------------------------- "+Devices.Count.ToString());

    }

    // Update is called once per frame
    void Update()
    {
    InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.CenterEye, Devices);
    if (Devices.Count > 0)
    {
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.centerEyePosition, out EyePos);
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.centerEyeRotation, out EyeRotation);
    }


    InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.RightHand, Devices);
    if (Devices.Count > 0)
    {
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.devicePosition, out RightHandPos);
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.trigger, out RightHandTrigger);
    if (RightHandTrigger > 0.01) Devices[Devices.Count - 1].SendHapticImpulse(0, RightHandTrigger, 0.05f);
    }

    InputDevices.GetDevicesAtXRNode(UnityEngine.XR.XRNode.LeftHand, Devices);
    if (Devices.Count > 0)
    {
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.devicePosition, out LeftHandPos);
    Devices[Devices.Count-1].TryGetFeatureValue(CommonUsages.trigger, out LeftHandTrigger);
    if (LeftHandTrigger > 0.01) Devices[Devices.Count - 1].SendHapticImpulse(0, LeftHandTrigger, 0.05f);

    }



    //Debug.Log(" RPos: " + RightHandPos.ToString()+" RTRig: "+RightHandTrigger.ToString());
    //Debug.Log(" LPos: " + LeftHandPos.ToString() + " LTRig: " + LeftHandTrigger.ToString());
    //Debug.Log(" EPos: " + EyePos.ToString() + " ERot: " + EyeRotation.ToString() + " T: "+EyePos.y.ToString());

    }
    }
     
  4. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    Another point that could be explain this behaviour.

    if I run this:
    ----------------------------------------------
    void Start()
    {
    InputDevices.GetDevices(Devices);
    foreach (var dev in Devices)
    {
    Debug.Log(string.Format("Device name '{0}' V: '{1}' M: '{2}' S:'{3}' .", dev.name, dev.isValid.ToString(), dev.manufacturer.ToString(),dev.serialNumber.ToString()));
    }

    Debug.Log("----------------------------------- "+Devices.Count.ToString());

    }

    ---------------------------------------------------------------

    I see the the serialNumber is empty, so the system can't detected differences between different controllers:

    This is the Debug Output in a valid case::

    Device name 'Spatial Controller - Right' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    Device name 'Spatial Controller - Left' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    ----------------------------------- 2

    This is the invalid case:

    Device name 'Spatial Controller - Right' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    Device name 'Spatial Controller - Left' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    Device name 'Spatial Controller - Left' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    Device name 'Spatial Controller - Left' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    Device name 'Spatial Controller - Right' V: 'True' M: 'Vendor: 1118 Product: 1627 Version 0' S:'' .
    UnityEngine.Debug:Log(Object)
    ----------------------------------- 5

    ----------------------------------------------------------------------------------------------------------------------------
    I'm supposing that the serialNumer slot empty could be the cause of the problem.
    Without the possibility to identify the controller the XR system should allow only one for every type.
     
  5. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    I discovered another detail.
    Today i tried the new input system and I created a binding with the XR controllers.
    Even the new input system fails and the Devices counter increments like my code. This is quite obvious because the issue is on the XR system.
    But trying i have discovered that the problem happens only if the reconnection occurs when the game is not playing.
    If I disconnect and reconnect while the game is playing all seems correct.
     
  6. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    Now I should have a Repro sequence:

    Unity version 2019.3.0f3.
    XR Management ; 3.06
    XR Legacy Input Helpers: 1.3.11
    Windows XR plugin : 2.0.3
    Input System prew.5 - 1.0.0 (used to display the bug only).
    Controllers Asus and Sansumg Odyssey behave in the same way.

    Create a binding with the XR controllers and check the presence in the Input-Debug Windows.
    Restarts the Unity Editor.
    Connect the controllers and press play (even a totally empty project).
    Check the Device presence and number in the Input-Debug Windows.
    Disconnect and reconnect the controllers all times you want and verify the condiction is correctly handled.
    Press stop button in the editor.
    Disconnect one or all two controllers.
    Press again the play button with the controllers always disconnected.
    The Input-Debug windows now will show wrongly that the controllers are still connected.
    Now reconnect the controllers and they will appear as new devices.
    If you repeat this sequence you will have several new controllers and only two of them will work.
    All these controllers have the validity bit as true.
    If you disconnect the Headset in the same way you will have two or more headset in the list


    This bug is strictly related to the editor in stop mode, but makes quite impossibile develop because all battery powered controllers tend to disconnect while you are writing code.
     
  7. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    Indeed a bug, repro'd locally, looking at it now.
     
  8. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    Can you please file a bug with the bug reporter and get me the Id? That way I can keep it tracked for you and you can follow when it's fixed.
     
  9. Mauro1965

    Mauro1965

    Joined:
    Aug 31, 2019
    Posts:
    27
    StayTalm_Unity likes this.