Search Unity

Resolved CommonUsages.grip and CommonUsages.trigger returning same thing

Discussion in 'XR Interaction Toolkit and Input' started by baaleos, May 1, 2021.

  1. baaleos

    baaleos

    Joined:
    May 12, 2018
    Posts:
    12
    This used to work for me on an old project, but for some reason, when I hold the grip button, instead of getting a single debug message, the update method spams the console output with not only the messages from the grip method, but also from the trigger method - its like CommonUsages.gripButton and CommonUsages.triggerButton are returning the same values now.

    Eg: the idea is that pressing the trigger or grip - will fire once, until it has a chance to reset.
    But for some reason, its not only spamming per frame - its also doing trigger, when grip is pressed and vice versa.



    Code (CSharp):
    1.    // Update is called once per frame
    2.     void Update()
    3.     {
    4.         CheckTrigger();
    5.         CheckGrip();
    6.     }
    7.  
    8.  
    9.     void CheckTrigger()
    10.     {
    11.         if(handController.inputDevice.TryGetFeatureValue(CommonUsages.triggerButton, out bool trigger))
    12.         {
    13.             TriggerPressed(trigger);
    14.         }
    15.     }
    16.     void CheckGrip()
    17.     {
    18.         if (handController.inputDevice.TryGetFeatureValue(CommonUsages.gripButton, out bool trigger))
    19.         {
    20.             GripPressed(trigger);
    21.         }
    22.     }
    23.  
    24.  
    25.     void TriggerPressed(bool trigger)
    26.     {
    27.         if(trigger && !isCharging)
    28.         {
    29.             isCharging = true;
    30.             Debug.Log("Trigger charging");
    31.         }
    32.         else if(!trigger  && isCharging)
    33.         {
    34.             isCharging = false;
    35.             Debug.Log("Trigger released");
    36.         }
    37.      
    38.      
    39.     }
    40.     void GripPressed(bool trigger)
    41.     {
    42.         if (trigger && !isCharging)
    43.         {
    44.             isCharging = true;
    45.             Debug.Log("Grip charging");
    46.             interactor.SignalGrab();
    47.         }
    48.         else if (!trigger && isCharging)
    49.         {
    50.             isCharging = false;
    51.             Debug.Log("Grip released");
    52.         }
    53.     }

    Actually - this thread can be ignored...
    Found the cause - both trigger and grip were looking at the same isCharging bool.
    Once I separated them out - it now works.
     
    Last edited: May 1, 2021