Search Unity

Question Open XR inputs TryGetFeatureValue always 0 for all Unity XR Input's CommonUsages

Discussion in 'XR Interaction Toolkit and Input' started by Titan1315, Jan 2, 2023.

  1. Titan1315

    Titan1315

    Joined:
    Mar 28, 2020
    Posts:
    1
    I'm using unity openXR plugin and I have been trying to fix this for 2 days but I have a static class for both my right and left hands to make inputs super easy to call however even when I press the button it returns nothing but false please help me I have asked stack overflow valem and anywhere else I can think and nothing. I have made sure I'm using the correct input system I have tried debugging my target device and it says it's a UnityEngine.XR.InputDevice and I have also made sure the script is active when I call it, lastly I tried debugging it in my static script and the actual common usage part returns false even though when I open he XR Interaction Debugger it shows everything working find. I'm on quest 2 please help.

    here's how I call it the helper

    Code (CSharp):
    1. Debug.Log(RightHand.AButtonDown());
    and here is the script with the helper

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR;
    5.  
    6. public static class RightHand
    7. {
    8.    private static InputDevice targetDevice;
    9.  
    10.    static RightHand()
    11.    {
    12.      
    13.        TryInitialize();
    14.    }
    15.  
    16.    private static void TryInitialize()
    17.    {
    18.        Debug.Log("ran inital");
    19.        List<InputDevice> devices = new List<InputDevice>();
    20.  
    21.        InputDeviceCharacteristics rightControllerCharacteristics = InputDeviceCharacteristics.Right | InputDeviceCharacteristics.Controller;
    22.  
    23.        InputDevices.GetDevicesWithCharacteristics(rightControllerCharacteristics, devices);
    24.  
    25.        foreach (var item in devices)
    26.        {
    27.            Debug.Log("ran log");
    28.            Debug.Log(item.name + item.characteristics);
    29.        }
    30.      
    31.        Debug.Log("right controler characteristics" + rightControllerCharacteristics);
    32.  
    33.        if (devices.Count > 0)
    34.        {
    35.            targetDevice = devices[0];
    36.        }
    37.  
    38.        Debug.Log(targetDevice);
    39.    }
    40.  
    41.    public static bool AButtonDown()
    42.    {
    43.        targetDevice.TryGetFeatureValue(CommonUsages.primaryButton, out bool primaryButtonOut);
    44.        if (primaryButtonOut)
    45.        {
    46.            return true;
    47.        }
    48.        else
    49.        {
    50.            return false;
    51.        }
    52.    }
    53. }