Input action maps help organize and manage different player controls in a game. They group related input actions so you can easily switch or handle controls.
Input action maps in Unity
InputActionMap actionMap = new InputActionMap("PlayerControls"); actionMap.AddAction("Jump", binding: "space"); actionMap.Enable();
var actionMap = new InputActionMap("Gameplay"); actionMap.AddAction("Move", binding: "<Keyboard>/w"); actionMap.AddAction("Jump", binding: "<Keyboard>/space"); actionMap.Enable();
var menuMap = new InputActionMap("Menu"); menuMap.AddAction("Navigate", binding: "<Gamepad>/dpad"); menuMap.AddAction("Select", binding: "<Gamepad>/buttonSouth"); menuMap.Enable();
This script creates a Player input action map with a Jump action bound to the spacebar. When space is pressed, it logs "Jump pressed!" to the console.
using UnityEngine; using UnityEngine.InputSystem; public class PlayerInputExample : MonoBehaviour { private InputActionMap playerActionMap; private InputAction jumpAction; void Awake() { playerActionMap = new InputActionMap("Player"); jumpAction = playerActionMap.AddAction("Jump", binding: "<Keyboard>/space"); jumpAction.performed += ctx => Debug.Log("Jump pressed!"); } void OnEnable() { playerActionMap.Enable(); } void OnDisable() { playerActionMap.Disable(); } }
Always enable your InputActionMap to start receiving input events.
You can disable maps to temporarily stop input without removing actions.
Use descriptive names for maps and actions to keep your code clear.
Input action maps group related input actions for better control management.
Enable or disable maps to control when inputs are active.
Bind actions to keys or buttons inside maps to handle player input cleanly.
Practice
What is the main purpose of an Input Action Map in Unity's Input System?
Solution
Step 1: Understand what Input Action Maps do
Input Action Maps group related input actions, like movement or UI controls, to organize inputs.Step 2: Compare with other options
Rendering graphics, storing settings, and audio playback are unrelated to input action maps.Final Answer:
To group related input actions for easier management -> Option DQuick Check:
Input Action Maps = Group inputs [OK]
- Confusing input maps with graphics or audio systems
- Thinking action maps store data permanently
- Assuming action maps handle rendering
Which of the following is the correct way to enable an InputActionMap named playerControls in C#?
?
Solution
Step 1: Recall the method to enable input action maps
The correct method to enable an InputActionMap isEnable().Step 2: Verify other options
Start(),Activate(), andRun()are not valid methods for InputActionMap.Final Answer:
playerControls.Enable(); -> Option CQuick Check:
Enable() activates input maps [OK]
- Using Start() instead of Enable()
- Confusing method names with other Unity components
- Forgetting to enable the action map before use
Given the following code snippet, what will be the output when playerControls is enabled and the player presses the jump button?
var playerControls = new PlayerInputActions();
playerControls.Player.Jump.performed += ctx => Debug.Log("Jump pressed");
playerControls.Player.Enable();
// Player presses jump buttonSolution
Step 1: Understand event subscription and enabling
The code subscribes to the Jump action's performed event and enables the Player action map.Step 2: Predict output on jump button press
When the jump button is pressed, the subscribed lambda logs "Jump pressed" once.Final Answer:
Jump pressed -> Option AQuick Check:
Subscribed event triggers log once [OK]
- Forgetting to enable the action map
- Expecting multiple logs without multiple subscriptions
- Confusing event names or missing subscription
What is wrong with this code snippet that tries to disable an input action map?
var controls = new PlayerInputActions();
controls.Player.Disable();
controls.Player.performed += ctx => Debug.Log("Action performed");Solution
Step 1: Check event subscription target
The code subscribes toperformedoncontrols.Player, which is an InputActionMap, not an InputAction.Step 2: Understand correct subscription
Events likeperformedbelong to InputActions, e.g.,controls.Player.Jump.performed, not the whole map.Final Answer:
The event subscription is on the action map instead of a specific action -> Option AQuick Check:
Subscribe events on actions, not maps [OK]
- Subscribing events on InputActionMap instead of InputAction
- Confusing Disable() method availability
- Assuming order of Enable/Disable affects subscription
You want to switch between two control schemes, Keyboard and Gamepad, during gameplay using input action maps. Which approach correctly handles this switch?
?
Solution
Step 1: Understand control scheme switching
Switching control schemes means activating one input action map and deactivating the other to avoid conflicts.Step 2: Evaluate options
Enabling both maps causes input conflicts; creating new actions wastes resources; ignoring schemes loses flexibility.Final Answer:
Disable the current action map and enable the other action map -> Option BQuick Check:
Switch by toggling action maps [OK]
- Enabling multiple action maps causing input conflicts
- Recreating actions unnecessarily
- Ignoring control scheme differences
Ready to prove it?
Pass the test and this pattern moves unknown
