Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Input System Button Triggers Multiple Times

So I've been playing around with the new Input System and things are starting to get a little frustrating. My issue is button pushes are firing multiple times. I've tried multiple settings with the type of action (eg Button, Pass Through etc), and Interactions being set to press only, or release or whatever, doesn't seem to matter. It'll either fire 2 times or 4 times depending on the settings.

I've got multiple controllers here for testing and as if that wasn't confusing enough, if a second or more player joins in, their button pushes trigger only once. It's always only player one's buttons who trigger multiple times. Does anyone know how to fix this?

Looks like I'm not the only one, looking at this forum thread.

Here is my very simple, basic test code just for reference.

public void GetInteractValues( InputAction.CallbackContext value )
 {
     if ( value.started )
         print("foo");
 }
like image 816
LexGear Avatar asked Apr 25 '26 11:04

LexGear


2 Answers

Coming into this late, but in case anyone else is confused: the multiple calls is intended behavior and is listed in the documentation (though the documentation took me a while to find).

Per this comment, check context.performed.

public void OnMyAction(InputAction.CallbackContext context)
{
    if (context.started)
        Debug.Log("Action was started");
    else if (context.performed)
        Debug.Log("Action was performed");
    else if (context.canceled)
        Debug.Log("Action was cancelled");
}
like image 184
Daniel Miller Avatar answered Apr 27 '26 16:04

Daniel Miller


An InputAction was raising multiple Started and Performed events when I pressed a button on the controller. Specifically, if a controller button press opened a new UI and the new UI subscribed to an InputAction that had the same bindings as the original InputAction, the new UI would receive the Started/Performed events immediately. This was undesirable.

To solve this, I had to add a "Tap" interaction to the InputAction, which overrode the default "Press" interaction. You can choose the interaction type by opening the InputActions file and press the "Interactions +" button in the Action Properties editor:

enter image description here

I also had to ensure my code both received Started and Performed before responding to the button.

like image 34
DoomGoober Avatar answered Apr 27 '26 15:04

DoomGoober



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!