Keypress detected twice when using Value action type and Invoke Unity Events behavior

I’ve noticed an uncommon behavior when using Invoke Unity Events and action type of Value. Pressing a keyboard key calls the callback method twice, while releasing the key calls it once.

I have created a Vector2, Value Action, and bound it to WASD (cardinal composite). Back on my Player Input, I’ve set it up with Invoke Unity Events, and set the callback to a quick debug method:

    public void Move(InputAction.CallbackContext context)
    {
        _movement = context.ReadValue<Vector2>();
        Debug.Log(_movement);
    }

However, I noticed pressing a key calls this method twice. And, funnily enough, setting the Action as Pass Through has the key press call the method only once.

Why is that happening? Is it expected?

With “Invoke Unity Events” you get a separate call for each action phase, started, performed and canceled. You can use context.phase to check which phase triggered the current callback.

When the action is set to “Value”, the event will be triggered three times: started and performed when the key is pressed and canceled when it’s released.

When the action is set to “Pass-Through”, there are no phases, you’ll only ever get a performed callback, one when the button is pressed and another one when it’s released.

This doesn’t matter much with digital controls like keyboard keys. But, as soon as you use analog controls like sticks or triggers, start and performed won’t be called at the same time and the difference becomes important.

The difference between “Value”, “Pass-Though” and “Button” is best explained on the InputActionType enum. You should also read the section on Predefined Interactions that explains when the events are triggred.