Search Unity

Question CallbackContext Canceled not being called with 2 Gamepads

Discussion in 'Input System' started by Kevin_Buckeejit, Jan 25, 2023.

  1. Kevin_Buckeejit

    Kevin_Buckeejit

    Joined:
    Sep 8, 2022
    Posts:
    8
    I have an issue with local multiplayer when 2 gamepads both input movement with left stick

    CallbackContext is not called for the 1st gamepad when it releases input and the 2nd gamepad continues input - the 2 players continue movement. (P2 is only receiving input from gamepad 2)

    I can see in Debug.Log that the ctx.canceled is not being called when the 1st gamepad stops input but the 2nd gamepad is receiving the ctx.canceled. The 2nd player stops moving but the 1st player continues with the animation loop because the ctx.canceled is never received from the 1st gamepad. If I give the 1st gamepad a new input it will then trigger a ctx.canceled and stop the player moving.

    This is the same issue for both P1 & P2 when there is input coming from both gamepads at the same time.

    The input action type for OnMove is set to Value, Vector2.

    Any info greatly appreciated!

    Code (CSharp):
    1. public void OnMove(InputAction.CallbackContext ctx)
    2.     {
    3.         var deviceID = ctx.control.device.deviceId;
    4.  
    5.         if (deviceID == player1DeviceID && gameObject.CompareTag("PlayerTeam1")) // Player 1 input
    6.         {
    7.             SetMoveInfo(ctx.ReadValue<Vector2>(), ctx.canceled);
    8.  
    9.             if (ctx.canceled)
    10.             {
    11.                 Debug.Log("P1 canceled" + deviceID);
    12.             }
    13.         }
    14.        
    15.         if (deviceID == player2DeviceID && gameObject.CompareTag("PlayerTeam2")) // Player 2 input
    16.         {
    17.             SetMoveInfo(ctx.ReadValue<Vector2>(), ctx.canceled);
    18.            
    19.             if (ctx.canceled)
    20.             {
    21.                 Debug.Log("P2 canceled" + deviceID);
    22.             }
    23.         }
     
  2. Kevin_Buckeejit

    Kevin_Buckeejit

    Joined:
    Sep 8, 2022
    Posts:
    8
    From a reply from reddit:

    I changed the action type from Value to "pass through" and I seem to be getting the behaviour that I am looking for.