Search Unity

Action Map Switching Ignoring Callback?

Discussion in 'Input System' started by TKG_Studios, Jul 30, 2022.

  1. TKG_Studios

    TKG_Studios

    Joined:
    Nov 3, 2020
    Posts:
    10
    I'm finally deciding to learn this new input system and it's going well, until I get to start learning about switching action maps.

    I just have two basic maps, Player and UI. The Button I'm using to test switching are the "T" (Switch to UI) and "Y" (Switch to Player) on the keyboard.

    I know that the maps are switching, because when I use Debug.Log(playerInput.currentActionMap); , it's telling me it's switching to the correct map. However when I test the "Submit" function, it does not fire the Debug.Log message I am looking for, and doesn't fire the Submit() function at all.

    Here is the relevant code:

    Code (CSharp):
    1.  //Player Script Reference
    2.         [SerializeField] internal PlayerScript playerScript;
    3.         private PlayerInput playerInput;
    4.         private PlayerInputActions playerInputActions;
    5.  
    6.         public float movementSpeed;
    7.         public float jumpHeight;
    8.         public int numberOfJumps;
    9.         [HideInInspector]
    10.         public int jumpsLeft = 3;
    11.  
    12.  
    13.         // Start is called before the first frame update
    14.         void Start()
    15.         {
    16.             //Grab Player Input Component
    17.             playerInput = GetComponent<PlayerInput>();
    18.        
    19.            
    20.             //Player Input Action Code
    21.             playerInputActions = new PlayerInputActions();
    22.             playerInputActions.Player.Enable();
    23.             playerInputActions.Player.Jump.performed += Jump;
    24.             playerInputActions.Player.Jump.started += Jump;
    25.             playerInputActions.Player.Move.performed += PlayerMove;
    26.        
    27.  
    28.             jumpsLeft = numberOfJumps; // Number of Jumps for Player Character
    29.         }
    30.  
    31.  
    32.         private void Update()
    33.         {
    34.             Debug.Log(playerInput.currentActionMap);
    35.                if (Keyboard.current.tKey.wasPressedThisFrame)
    36.             {
    37.                 playerInputActions.Player.Disable();
    38.                 playerInput.SwitchCurrentActionMap("UI");
    39.             }
    40.             if (Keyboard.current.yKey.wasPressedThisFrame)
    41.             {
    42.                 playerInputActions.Player.Enable();
    43.            
    44.                 playerInput.SwitchCurrentActionMap("Player");
    45.             }
    46.  
    47.         }
    48.  
    49.     public void Jump(InputAction.CallbackContext context)
    50.         {
    51.             if (context.performed)
    52.             {
    53.                 jumpsLeft -= 1;
    54.             }
    55.             if (jumpsLeft <= 0)
    56.             {
    57.                 jumpsLeft = 0;
    58.             }
    59.             if (jumpsLeft > 0)
    60.             {
    61.                 playerScript.rigidBody.velocity = new Vector2(0, jumpHeight);
    62.             }
    63.         }
    64.  
    65.      public void Submit(InputAction.CallbackContext context)
    66.         {
    67.             if (context.started)
    68.             {
    69.                 Debug.Log("Enter Action " + context);
    70.             }
    71.         }
    72.     }
    73. }
    I'm using the Unity Events behavior, and yes I have applied the PlayerMovement.Submit to the Submit event in the inspector.

    Anyone know what might be going wrong here?
     

    Attached Files: