In this lesson, you will learn how to replace Unity’s legacy input handling with the modern Input System package to enable more flexible, cross-platform controls.
Why Switch from Legacy?
Previously, we used the Input.GetKey() method, which is simple but limited. It tightly couples your code to specific hardware (like a keyboard). The New Input System acts as a middleman between your game logic and the actual hardware. By abstracting inputs into "Actions," you can swap between a controller, a mouse, or a touchscreen without rewriting your scripts.
Installation
Because the new system is not part of the core Unity installation, we must use the Unity Package Manager (which we covered in Lesson 6).
- Open Window > Package Manager.
- Click the Packages dropdown and select Unity Registry.
- Search for Input System.
- Click Install.
Unity will prompt you to restart the editor to disable the legacy Input Manager and enable the new system. Accept this restart to ensure the new drivers take over.
Configuring the System
Once installed, the system needs to know what inputs you care about. We do this by creating an Input Actions asset:
- Right-click in your Project Window (where we manage our assets, per Lesson 3).
- Go to Create > Input Actions.
- Name it
PlayerControls.
Double-clicking this asset opens an editor window where you can define "Actions" (like Jump or Move). Instead of checking if a specific button is pressed, your code will now listen for these named actions:
// Instead of Input.GetKey(KeyCode.Space), we use:
void OnJump() {
// Logic for jumping happens here regardless of the input device
}
This setup separates "what the player wants to do" (Jump) from "how they do it" (pressing a spacebar or a gamepad button). By configuring these maps, your game becomes instantly compatible with multiple devices, ensuring your controls feel professional across any platform.
Key Takeaway: The New Input System replaces hardware-specific polling with an Action-based workflow, allowing your game to support diverse input devices without changing your core logic.