The New Input System in Unity helps you read player actions like keyboard presses, mouse clicks, or gamepad buttons in a simple and flexible way.
New Input System overview in Unity
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
private PlayerInputActions inputActions;
private void Awake()
{
inputActions = new PlayerInputActions();
}
private void OnEnable()
{
inputActions.Enable();
}
private void OnDisable()
{
inputActions.Disable();
}
private void Update()
{
Vector2 move = inputActions.Player.Move.ReadValue<Vector2>();
// Use move vector to move player
}
}You create an Input Actions asset in Unity to define controls, then generate a C# class to access them.
Enable input actions when the object is active, and disable them when not to save resources.
inputActions.Player.Jump.performed += ctx => Jump();
Vector2 moveInput = inputActions.Player.Move.ReadValue<Vector2>();
inputActions.Player.Enable(); // Later inputActions.Player.Disable();
This simple program shows how to read movement input and listen for a jump button press using the New Input System.
using UnityEngine; using UnityEngine.InputSystem; public class SimplePlayerController : MonoBehaviour { private PlayerInputActions inputActions; private void Awake() { inputActions = new PlayerInputActions(); } private void OnJump(InputAction.CallbackContext context) { Debug.Log("Jump pressed!"); } private void OnEnable() { inputActions.Enable(); inputActions.Player.Jump.performed += OnJump; } private void OnDisable() { inputActions.Player.Jump.performed -= OnJump; inputActions.Disable(); } private void Update() { Vector2 move = inputActions.Player.Move.ReadValue<Vector2>(); Debug.Log($"Moving: {move}"); } }
Remember to generate the C# class from your Input Actions asset before using it in code.
Use the Input Debugger window in Unity to see what inputs are detected during play.
The New Input System lets you handle many input devices easily.
You define actions in an asset and use generated code to read inputs.
Enable and disable input actions to control when input is active.
Practice
Solution
Step 1: Understand the role of input systems
The New Input System is designed to manage inputs from devices like keyboard, mouse, gamepads, etc.Step 2: Compare with other options
Options B, C, and D relate to graphics, physics, or modeling, not input handling.Final Answer:
To handle multiple input devices easily and flexibly -> Option BQuick Check:
New Input System = device input management [OK]
- Confusing input system with graphics or physics
- Thinking it only handles keyboard input
- Assuming it creates game assets
Solution
Step 1: Recall method names in New Input System
The method to activate an input action is called Enable(), not Start(), Activate(), or Run().Step 2: Confirm syntax correctness
inputAction.Enable(); is the correct syntax to enable the action.Final Answer:
inputAction.Enable(); -> Option DQuick Check:
Enable() activates input actions [OK]
- Using Start() instead of Enable()
- Confusing method names with Activate() or Run()
- Forgetting parentheses after method name
var moveAction = playerInput.actions["Move"]; moveAction.Enable(); var value = moveAction.ReadValue<Vector2>(); Debug.Log(value);
What does
value represent?Solution
Step 1: Understand ReadValue<Vector2>()
This method reads the current input value as a Vector2, typically for movement directions.Step 2: Analyze the variable 'value'
Since moveAction is enabled and ReadValue<Vector2>() is called, value holds the 2D input vector from the Move action.Final Answer:
The current 2D vector input from the Move action -> Option AQuick Check:
ReadValue<Vector2>() returns Vector2 input [OK]
- Thinking it returns a boolean
- Confusing value with action name or ID
- Not enabling the action before reading
var jumpAction = playerInput.actions["Jump"]; jumpAction.ReadValue<float>(); jumpAction.Enable();
Solution
Step 1: Check the order of method calls
The code reads the input value before enabling the action, which means no input is active yet.Step 2: Understand correct usage
Enable() must be called before reading values to get valid input data.Final Answer:
The action is read before it is enabled -> Option AQuick Check:
Enable() must come before ReadValue() [OK]
- Reading input before enabling action
- Assuming ReadValue<float>() is invalid
- Thinking action names must be changed
Solution
Step 1: Understand disabling input actions
Calling Disable() on the actions disables all input reading cleanly and temporarily.Step 2: Evaluate other options
Deleting assets is destructive, setting callbacks to null is error-prone, ignoring inputs wastes resources.Final Answer:
CallplayerInput.actions.Disable()to disable all input actions -> Option CQuick Check:
Disable() cleanly stops input during cutscenes [OK]
- Deleting input assets instead of disabling
- Nullifying callbacks causing errors
- Ignoring inputs wastes CPU
Ready to prove it?
Pass the test and this pattern moves unknown
