INPUT • GAMEPLAY SCRIPTING

INPUT.GETKEY / GETKEYDOWN NOT WORKING IN UNITY

Player jump or attack button presses are randomly missed, unresponsive, or completely ignored during gameplay.

Why Are Inputs Missed or Ignored?

There are three primary reasons why Input.GetKeyDown() fails to register in Unity:

  • 1. Polling Input in FixedUpdate(): FixedUpdate() runs at a fixed 50Hz (every 20ms), while Update() runs with every rendered screen frame (e.g. 144Hz = 6.9ms). Input.GetKeyDown is only true for one single render frame. If you tap the key in a frame where FixedUpdate does not tick, the input is permanently lost!
  • 2. UI Canvas Raycast Blocking: An invisible full-screen UI Image or panel has Raycast Target checked, intercepting mouse clicks or touch taps before they reach the game world.
  • 3. Active Input System Mismatch: The project is configured for the New Input System Package while the script is using the legacy UnityEngine.Input API.

Step-by-Step Fix

  1. Always Poll Inputs in Update():

    Read keydown flags inside Update(), store them in a boolean variable, and execute the physical force in FixedUpdate():

    private bool jumpRequested;
    
    void Update()
    {
        // ✅ Never missed in Update!
        if (Input.GetButtonDown("Jump"))
        {
            jumpRequested = true;
        }
    }
    
    void FixedUpdate()
    {
        if (jumpRequested)
        {
            rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
            jumpRequested = false; // Reset
        }
    }
  2. Disable Raycast Target on Non-Interactive UI:

    Select your UI Canvas backgrounds, health bars, and HUD overlays. In the Image and TextMeshProUGUI components, UNCHECK Raycast Target.

  3. Check Active Input Handling Setting:

    Go to Project Settings > Player > Other Settings > Active Input Handling. If using legacy code alongside new controllers, select Both.

Related Guides & Errors

Frequently Asked Questions

Input.GetKeyDown(KeyCode.Space) is true for exactly one single frame when the key is first pressed down (ideal for jumping, shooting, opening menus). Input.GetKey(KeyCode.W) remains true continuously for every frame the key is held down (ideal for walking, vehicle throttle, sustained laser fire).