When using a gamepad, the canceled event of Button Action fires as soon as the button is pressed

Unity 2022.3.49f1, Input system 1.11.1

as shown

image

Action Attack is bound to the J key of the keyboard, the left mouse button, and the X button of the xbox controller.

void OnEnable()
{
    InputActs.Player.Attack.started += OnAttackStarted;
    InputActs.Player.Attack.canceled += OnAttackCanceled;
}

private void OnAttackStarted(InputAction.CallbackContext context)
{
    Debug.Log("Attack started");
}

private void OnAttackCanceled(InputAction.CallbackContext context)
{
    Debug.Log("Attack canceled");
}

I have listened to the Attack’s started and canceled events in my code.

My question is, how can I get the gamepad button to also trigger the canceled event only when it is released

Solved.

The unity of this project was upgraded from 2022.3.12f1 to 2022.3.49f1, which caused the input system to be upgraded from 1.7 to 1.11, and the original Input Actions resource in the project was generated by version 1.7 and uses the C# files it generates, and that’s where things went wrong.