0
0
Unityframework~3 mins

Why Input action maps in Unity? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could change your game controls anytime without rewriting your code?

The Scenario

Imagine you are making a game where the player can jump, run, and shoot. You write separate code to check every key press manually, like checking if the spacebar is pressed for jump or if the mouse button is clicked for shooting.

The Problem

This manual way gets messy fast. You have to write many if-statements, and when you want to change controls or add a new action, you must hunt through your code to update everything. It's easy to make mistakes and hard to keep track of all inputs.

The Solution

Input action maps let you group all player actions and their controls in one place. You define actions like 'Jump' or 'Shoot' and assign keys or buttons to them. Then your game listens for these actions instead of raw keys, making your code cleaner and easier to manage.

Before vs After
Before
if (Input.GetKeyDown(KeyCode.Space)) { Jump(); }
if (Input.GetMouseButtonDown(0)) { Shoot(); }
After
playerInput.actions["Jump"].performed += ctx => Jump();
playerInput.actions["Shoot"].performed += ctx => Shoot();
What It Enables

You can easily change controls, support multiple devices, and keep your input code organized and scalable.

Real Life Example

In a multiplayer game, you want players to customize their controls. Input action maps let you save and load different control schemes without rewriting your game logic.

Key Takeaways

Manual input checks become hard to manage as your game grows.

Input action maps group actions and controls cleanly.

This makes your game easier to update and supports flexible control setups.