Issue with Unity Input System - Running and Jumping Actions at the same time

Hello,

I’m encountering an issue with the Unity Input System and its handling of input actions. I have set up two action maps: “CharacterMovement” and “CharacterJump.”

In the “CharacterMovement” action map, I have configured the “Run” action to activate when I press the left shift button. In the “CharacterJump” action map, I have configured the “Jump” action to activate when I press the Space button.

The problem I’m facing is that when I have the “Run” button held down and try to press the “Jump” button, the “Jump” action’s function is not being triggered. Conversely, if I hold the “Jump” button, the “Run” action doesn’t work.

System Information:

  • Unity version: 2021.3.8f1
  • Input System version: 1.4.4

Below, I will provide the section of the code where I handle these actions and include images to demonstrate how they are configured in the Input Actions System.

    private void Run(InputAction.CallbackContext context)
    {
        Debug.Log("RUNNING");
        isRunning = true;
    }

    private void Jump(InputAction.CallbackContext context)
    {
        Debug.Log("NOT BEING CALLED WHEN PLAYER IS RUNNING");
        if (!isJumping)
        {
            animator.SetTrigger(isJumpingHash);
        }
    }

    private void enablePlayerInputs()
    {
        playerInput.Enable();
        playerInput.CharacterMovement.KeyboardWalk.performed += KeyboardMove;
        playerInput.CharacterMovement.KeyboardWalk.canceled += StopKeyboardMove; 
        playerInput.CharacterMovement.MouseWalk.performed += MouseMove; 
        playerInput.CharacterMovement.MouseWalk.canceled += StopMouseMove; 
        playerInput.CharacterMovement.Run.started += Run; 
        playerInput.CharacterMovement.Run.canceled += StopRun; 
        playerInput.CharacterJump.Jump.started += Jump;
        playerInput.CharacterJump.Jump.canceled += StopJump; 
    }




Thank you in advance for your help.

Your setup isn’t quite correct. Action Maps are separate maps and don’t work together afaik. You would have an action map for gameplay, and another action map for UI, for example. When the menus are open, you enable the UI action map and then all the controls defined in the UI action map is active, and when the menus are closed and the player is moving around, you have the other action map active.

In your setup, when you jump, the jump map is activated and the movement map can’t activate, and vice versa. Movement and Jumping should be in the same action map.

Initially, I had both running and jumping actions within the same action map, ‘CharacterMovement.’ However, I encountered the same issue even when they were in the same action map. So I tried separating them to see if it would resolve the problem, but it didn’t.

I believe they should be in the same action map. If that doesn’t work, you may have a different issue. The code looks fine - at least the bits you shared.

I found that the issue occurred when I assigned the Jump command to the spacebar and the Run command to the Left Shift key. Apparently, this combination doesn’t work correctly. If I change either the Jump or Run command to any other button, it works fine. I believe it has to do with simultaneous key registration on the keyboard.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms