Lesson 24 +10 XP

Modern Input System

Modern Input System

Unity's newer Input System package is an event-driven alternative to the legacy Input Manager, designed to support multiple devices and complex control layouts.

Setting Up the Input System

  1. Install the Input System package from the Package Manager.
  2. In Project Settings, set Active Input Handling to Both or Input System Package (New).
  3. Create an Input Actions asset in your project.

Action Maps and Bindings

An Input Actions asset organizes controls into:

  • Action Maps: Groups of controls (e.g. "Player", "Menu", "Driving").
  • Actions: Input abstract events (e.g. "Move", "Jump", "Fire").
  • Bindings: Physical keys or gamepad buttons mapped to an action.

The PlayerInput Component

To hook up actions without complex coding:

  1. Add a Player Input component to your player GameObject.
  2. Link your Input Actions asset to the component.
  3. Select a Behavior option (e.g. Send Messages or Invoke Unity Events).

If using Unity Events, you can assign methods directly in the Inspector:

using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public void OnJump(InputValue value)
    {
        if (value.isPressed)
        {
            Debug.Log("Jump Action Triggered!");
        }
    }

    public void OnMove(InputValue value)
    {
        Vector2 inputVec = value.Get<Vector2>();
        Debug.Log("Move input: " + inputVec);
    }
}

TL;DR

  • The modern Input System is event-driven and device-independent.
  • Actions define intent (e.g. "Jump"), and Bindings assign keys (e.g. "Space").
  • Use the Player Input component to connect actions to script callbacks easily.
  • Script callbacks receive InputValue parameters containing context data.