Bird
Raised Fist0
Unityframework~20 mins

Input action maps in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Input Action Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output when reading a button press?

Consider this Unity C# code snippet using the new Input System. What will be printed when the button is pressed?

Unity
using UnityEngine;
using UnityEngine.InputSystem;

public class TestInput : MonoBehaviour
{
    public InputAction action;

    void OnEnable()
    {
        action.Enable();
        action.performed += ctx => Debug.Log("Button pressed");
    }

    void OnDisable()
    {
        action.Disable();
    }
}
AButton pressed is printed continuously every frame
BAn error occurs because action is not initialized
CNothing is printed unless the action is enabled and the button is pressed
DButton pressed is printed once when the script starts
Attempts:
2 left
💡 Hint

Think about when the performed event triggers and what enabling the action does.

🧠 Conceptual
intermediate
1:30remaining
Which InputAction type is best for continuous movement?

In Unity's Input System, which InputAction type should you use to get smooth, continuous movement input like from a joystick or WASD keys?

AValue
BButton
CPassThrough
DToggle
Attempts:
2 left
💡 Hint

Continuous movement needs a value that changes over time, not just a press or release.

🔧 Debug
advanced
2:30remaining
Why does this InputAction not trigger?

Given this code, why does the performed callback never run?

Unity
public class PlayerInput : MonoBehaviour
{
    public InputAction jumpAction;

    void Start()
    {
        jumpAction.performed += ctx => Debug.Log("Jump!");
    }

    void OnEnable()
    {
        // jumpAction.Enable();
    }

    void OnDisable()
    {
        jumpAction.Disable();
    }
}
AThe jumpAction variable is null and causes a NullReferenceException
BThe callback is added too late in Start(), it should be in Awake()
CThe performed event only triggers on release, not press
DThe action is never enabled, so it does not listen for input
Attempts:
2 left
💡 Hint

Check if the action is enabled anywhere.

📝 Syntax
advanced
2:00remaining
Identify the syntax error in this InputAction callback setup

Which option contains the correct syntax to subscribe to an InputAction's performed event?

Unity
InputAction action = new InputAction();
Aaction.performed = ctx => Debug.Log("Action performed");
Baction.performed += (InputAction.CallbackContext context) => { Debug.Log("Action performed"); };
Caction.performed += context => Debug.Log("Action performed");
Daction.performed += delegate { Debug.Log("Action performed"); };
Attempts:
2 left
💡 Hint

Remember how to add event handlers in C# with lambda or delegate syntax.

🚀 Application
expert
3:00remaining
How to read a Vector2 from an InputAction and use it for movement?

You have an InputAction named moveAction set to type Value with a Vector2 binding. How do you read its value inside Update() to move a character?

Unity
public class PlayerController : MonoBehaviour
{
    public InputAction moveAction;
    public float speed = 5f;

    void OnEnable() => moveAction.Enable();
    void OnDisable() => moveAction.Disable();

    void Update()
    {
        // Fill in the code here
    }
}
A
Vector2 input = moveAction.ReadValue<Vector2>();
transform.Translate(input * speed * Time.deltaTime);
B
Vector2 input = moveAction.Read<Vector2>();
transform.position += input * speed;
C
Vector2 input = moveAction.value<Vector2>();
transform.Translate(input * speed);
D
Vector2 input = moveAction.Get<Vector2>();
transform.position += input * speed * Time.deltaTime;
Attempts:
2 left
💡 Hint

Look for the correct method to read the current value of an InputAction.

Practice

(1/5)
1.

What is the main purpose of an Input Action Map in Unity's Input System?

easy
A. To handle audio playback
B. To render graphics on the screen
C. To store game settings permanently
D. To group related input actions for easier management

Solution

  1. Step 1: Understand what Input Action Maps do

    Input Action Maps group related input actions, like movement or UI controls, to organize inputs.
  2. Step 2: Compare with other options

    Rendering graphics, storing settings, and audio playback are unrelated to input action maps.
  3. Final Answer:

    To group related input actions for easier management -> Option D
  4. Quick Check:

    Input Action Maps = Group inputs [OK]
Hint: Remember: Action maps group inputs logically [OK]
Common Mistakes:
  • Confusing input maps with graphics or audio systems
  • Thinking action maps store data permanently
  • Assuming action maps handle rendering
2.

Which of the following is the correct way to enable an InputActionMap named playerControls in C#?

?
easy
A. playerControls.Activate();
B. playerControls.Start();
C. playerControls.Enable();
D. playerControls.Run();

Solution

  1. Step 1: Recall the method to enable input action maps

    The correct method to enable an InputActionMap is Enable().
  2. Step 2: Verify other options

    Start(), Activate(), and Run() are not valid methods for InputActionMap.
  3. Final Answer:

    playerControls.Enable(); -> Option C
  4. Quick Check:

    Enable() activates input maps [OK]
Hint: Use Enable() to start input action maps [OK]
Common Mistakes:
  • Using Start() instead of Enable()
  • Confusing method names with other Unity components
  • Forgetting to enable the action map before use
3.

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 button
medium
A. Jump pressed
B. No output
C. NullReferenceException
D. Jump pressed twice

Solution

  1. Step 1: Understand event subscription and enabling

    The code subscribes to the Jump action's performed event and enables the Player action map.
  2. Step 2: Predict output on jump button press

    When the jump button is pressed, the subscribed lambda logs "Jump pressed" once.
  3. Final Answer:

    Jump pressed -> Option A
  4. Quick Check:

    Subscribed event triggers log once [OK]
Hint: Enabling action map triggers subscribed events [OK]
Common Mistakes:
  • Forgetting to enable the action map
  • Expecting multiple logs without multiple subscriptions
  • Confusing event names or missing subscription
4.

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");
medium
A. The event subscription is on the action map instead of a specific action
B. Disable() method does not exist on InputActionMap
C. You cannot disable an action map before subscribing to events
D. The code should call Enable() before Disable()

Solution

  1. Step 1: Check event subscription target

    The code subscribes to performed on controls.Player, which is an InputActionMap, not an InputAction.
  2. Step 2: Understand correct subscription

    Events like performed belong to InputActions, e.g., controls.Player.Jump.performed, not the whole map.
  3. Final Answer:

    The event subscription is on the action map instead of a specific action -> Option A
  4. Quick Check:

    Subscribe events on actions, not maps [OK]
Hint: Subscribe events on actions, not action maps [OK]
Common Mistakes:
  • Subscribing events on InputActionMap instead of InputAction
  • Confusing Disable() method availability
  • Assuming order of Enable/Disable affects subscription
5.

You want to switch between two control schemes, Keyboard and Gamepad, during gameplay using input action maps. Which approach correctly handles this switch?

?
hard
A. Use only one action map and ignore control schemes
B. Disable the current action map and enable the other action map
C. Create new input actions every time you switch
D. Enable both action maps at the same time

Solution

  1. Step 1: Understand control scheme switching

    Switching control schemes means activating one input action map and deactivating the other to avoid conflicts.
  2. Step 2: Evaluate options

    Enabling both maps causes input conflicts; creating new actions wastes resources; ignoring schemes loses flexibility.
  3. Final Answer:

    Disable the current action map and enable the other action map -> Option B
  4. Quick Check:

    Switch by toggling action maps [OK]
Hint: Toggle action maps to switch control schemes [OK]
Common Mistakes:
  • Enabling multiple action maps causing input conflicts
  • Recreating actions unnecessarily
  • Ignoring control scheme differences
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard