0
0
Unityframework~20 mins

Input action maps in Unity - Practice Problems & Coding Challenges

Choose your learning style9 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.