Course contentsShow
← Unity Game Development
Lesson 171 of 8283. Physics and InteractionFree lesson

Mapping Actions to Physical Device Inputs

Bind specific keyboard, mouse, and gamepad inputs to abstract actions within the Input Action Asset using binding schemes.

In this lesson, you will learn how to bridge the gap between abstract player intentions and actual hardware buttons using the Input Action Asset.

Bridging Logic and Hardware

In the previous lesson, we defined abstract "Actions" (like Jump or Move) inside our Input Action Asset. However, those actions are currently empty containers; they don't know which button should trigger them. "Mapping" is the process of telling Unity that the Jump action should be triggered by the Space key on a keyboard or the South button on a gamepad.

How Mapping Works

When you open your Input Action Asset, you’ll see your defined actions. By clicking the plus icon next to an action, you create a Binding. A binding acts as a translator. You simply select the "Path" for the binding and navigate the input hierarchy to choose the specific device button you want to link.

For example, if you want a Fire action, you would create two bindings:

  1. Binding 1 (Keyboard): Set the path to Keyboard/space.
  2. Binding 2 (Gamepad): Set the path to Gamepad/rightTrigger.

Because both bindings are mapped to the same "Fire" action, your C# script doesn't need to check if the user pressed the Spacebar or the Trigger. Your script simply listens for the Fire action, and Unity automatically handles the physical hardware translation for you:

// The script doesn't care if it came from a keyboard or controller!
void OnFire(InputValue value) 
{
    // Logic for firing a projectile triggered by the Input Action
    FireWeapon();
}

Why Use Binding Schemes?

You might wonder why we don't just hard-code inputs. By using bindings, you decouple your game logic from the hardware. If you decide later that "Space" is a bad jump button, you only change the path in your Input Action Asset, not a single line of your code. This makes your game naturally modular and ready for cross-platform play without rewriting your physics or movement systems.

Key Takeaway: Bindings decouple your game logic from specific hardware by mapping physical inputs to abstract actions within your Input Action Asset.