0
0
Unityframework~20 mins

New Input System overview in Unity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
New Input System Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Input Action callback?

Consider this Unity C# code snippet using the New Input System:

using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public InputAction jumpAction;

    void OnEnable()
    {
        jumpAction.Enable();
        jumpAction.performed += ctx => Debug.Log($"Jump performed at {ctx.time}");
    }

    void OnDisable()
    {
        jumpAction.Disable();
    }
}

If the player presses the jump button at game time 5.2 seconds, what will be printed?

Unity
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public InputAction jumpAction;

    void OnEnable()
    {
        jumpAction.Enable();
        jumpAction.performed += ctx => Debug.Log($"Jump performed at {ctx.time}");
    }

    void OnDisable()
    {
        jumpAction.Disable();
    }
}
ANo output because jumpAction is not enabled
BJump performed at 0
CJump performed at ctx.time
DJump performed at 5.2
Attempts:
2 left
💡 Hint

Look at the ctx.time property in the callback. It gives the time of the input event.

🧠 Conceptual
intermediate
1:30remaining
Which Input System component stores the player's input bindings?

In Unity's New Input System, where are the player's input bindings (like keyboard keys or gamepad buttons) stored?

AInputUser
BInputActionAsset
CInputControlScheme
DInputActionMap
Attempts:
2 left
💡 Hint

Think about the asset that holds all actions and their bindings.

Predict Output
advanced
2:00remaining
What is the output of this InputAction value reading?

Given this code snippet:

var moveAction = new InputAction(type: InputActionType.Value, binding: "/leftStick");
moveAction.Enable();
var value = moveAction.ReadValue<Vector2>();
Debug.Log(value);

If the left stick is centered (not moved), what will be printed?

Unity
var moveAction = new InputAction(type: InputActionType.Value, binding: "<Gamepad>/leftStick");
moveAction.Enable();
var value = moveAction.ReadValue<Vector2>();
Debug.Log(value);
A(0.0, 0.0)
B(1.0, 1.0)
C(0.5, 0.5)
DNullReferenceException
Attempts:
2 left
💡 Hint

Think about the default position of a gamepad's left stick when untouched.

🔧 Debug
advanced
2:00remaining
Why does this InputAction callback never run?

Look at this code:

public InputAction fireAction;

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

void Update()
{
    if (fireAction.triggered)
        Debug.Log("Triggered");
}

Why does pressing the fire button never print "Fire!"?

Unity
public InputAction fireAction;

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

void Update()
{
    if (fireAction.triggered)
        Debug.Log("Triggered");
}
AThe performed event only fires in Update, not Start
BThe lambda syntax is incorrect
CfireAction is never enabled, so callbacks don't run
Dtriggered is false because fireAction is disabled
Attempts:
2 left
💡 Hint

Check if the InputAction is enabled before use.

🧠 Conceptual
expert
2:30remaining
Which feature allows multiple players to use separate input devices simultaneously?

In Unity's New Input System, what feature lets you manage multiple players each with their own input devices, so they don't interfere with each other?

AInputUser
BInputBindingMask
CInputActionMap
DInputControlScheme
Attempts:
2 left
💡 Hint

Think about the system that tracks users and their devices.