UNITY INPUT SYSTEM BEGINNER GUIDE

Migrate away from legacy Input.GetKey to Unity's modern, event-driven Input System with seamless support for Keyboard, Gamepad controllers, and Mobile Touchscreens.

Quick Answer

Install the com.unity.inputsystem package via Package Manager. Enable Active Input Handling: Both in Project Settings. Create an InputActionAsset, or read input directly in C# using Gamepad.current or Keyboard.current without polling strings.

1

Direct C# Input System Reading Example

ModernPlayerInput.cs (C#)
using UnityEngine;
using UnityEngine.InputSystem;

public class ModernPlayerInput : MonoBehaviour
{
    [Header("Input Values")]
    public Vector2 MoveVector { get; private set; }
    public bool IsFirePressed { get; private set; }
    public bool IsJumpPressed { get; private set; }

    private void Update()
    {
        Vector2 input = Vector2.zero;

        // 1. Read Keyboard
        if (Keyboard.current != null)
        {
            if (Keyboard.current.wKey.isPressed || Keyboard.current.upArrowKey.isPressed) input.y += 1f;
            if (Keyboard.current.sKey.isPressed || Keyboard.current.downArrowKey.isPressed) input.y -= 1f;
            if (Keyboard.current.aKey.isPressed || Keyboard.current.leftArrowKey.isPressed) input.x -= 1f;
            if (Keyboard.current.dKey.isPressed || Keyboard.current.rightArrowKey.isPressed) input.x += 1f;

            IsFirePressed = Keyboard.current.spaceKey.isPressed;
        }

        // 2. Read Gamepad (Xbox / PlayStation / Mobile Controller)
        if (Gamepad.current != null)
        {
            Vector2 stick = Gamepad.current.leftStick.ReadValue();
            if (stick.sqrMagnitude > 0.05f)
            {
                input = stick; // Analog stick precision
            }

            if (Gamepad.current.rightTrigger.isPressed || Gamepad.current.buttonSouth.isPressed)
            {
                IsFirePressed = true;
            }
        }

        MoveVector = input;
    }
}

Encountering Input System Compiler or Runtime Errors?

Check out our error solutions: InvalidOperationException Fix • Input Manager Deprecation Fix

Apply Input to Vehicles

Advanced Input Action Maps and Runtime Rebinding

Creating accessibility-friendly games requires allowing players to rebind keyboard, mouse, and gamepad controls during live gameplay. Unity's modern Input System includes native asynchronous rebinding APIs that listen for player key presses and automatically update JSON configuration bindings.

RuntimeRebinder.cs (C#)
using UnityEngine;
using UnityEngine.InputSystem;

public class RuntimeRebinder : MonoBehaviour
{
    [SerializeField] private InputActionReference jumpAction;

    public void StartInteractiveRebind()
    {
        jumpAction.action.Disable();

        var rebindOp = jumpAction.action.PerformInteractiveRebinding()
            .WithControlsExcluding("Mouse")
            .OnComplete(operation =>
            {
                Debug.Log($"Rebound jump to: {jumpAction.action.bindings[0].effectivePath}");
                operation.Dispose();
                jumpAction.action.Enable();
            })
            .Start();
    }
}

Touchscreen Virtual Joysticks Integration

The Input System package includes an On-Screen Stick and On-Screen Button component. Adding these to UI canvas elements binds touch drag gestures directly to your existing Vector2 flight stick Action Maps without writing custom touch coordinate math.