0
0
Unityframework~10 mins

New Input System overview in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - New Input System overview
Start
Create Input Actions
Generate C# Class
Enable Input Actions
Listen for Input Events
Respond to Input
Disable Input Actions
End
This flow shows how the new input system in Unity works from creating input actions to responding to input events.
Execution Sample
Unity
var controls = new PlayerControls();
controls.Enable();
controls.Player.Jump.performed += ctx => Jump();
void Jump() {
  Debug.Log("Jump!");
}
This code creates input controls, enables them, listens for a jump action, and runs a jump method when triggered.
Execution Table
StepActionEvaluationResult
1Create PlayerControls instancevar controls = new PlayerControls()controls object created with input actions
2Enable input actionscontrols.Enable()Input system starts listening for inputs
3Subscribe to Jump actioncontrols.Player.Jump.performed += ctx => Jump()Jump method linked to Jump input event
4Player presses jump buttonJump input detectedJump() method called
5Jump() runsDebug.Log("Jump!")Console prints 'Jump!'
6Disable input actionscontrols.Disable()Input system stops listening for inputs
💡 Input actions disabled or game ends, stopping input listening
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
controlsnullPlayerControls instanceEnabledJump event subscribedJump event triggeredDisabled
Key Moments - 3 Insights
Why do we need to call controls.Enable()?
controls.Enable() starts the input system listening for input events. Without it, input actions won't detect any input, as shown in step 2 of the execution_table.
What happens if we don't unsubscribe from input events?
If you don't unsubscribe, the event handler stays active and can cause unexpected behavior or memory leaks. The example shows subscribing but disabling input stops listening (step 6).
How does the Jump() method get called?
Jump() is called when the Jump input action is performed, as linked in step 3 and triggered in step 4 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the state of 'controls' after step 2?
AJump event is subscribed
BInput actions are disabled
CInput system is listening for inputs
DJump method has been called
💡 Hint
Check the 'Result' column in step 2 of the execution_table
At which step does the Jump() method get called?
AStep 4
BStep 3
CStep 6
DStep 5
💡 Hint
Look at the 'Action' and 'Result' columns for when Jump() runs
If controls.Disable() is never called, what happens?
AInput system stops listening automatically
BInput system keeps listening for inputs
CJump() method never runs
DPlayerControls instance is destroyed
💡 Hint
Refer to the 'exit_note' and step 6 in the execution_table
Concept Snapshot
New Input System in Unity:
- Create Input Actions asset
- Generate C# class from asset
- Instantiate and Enable controls
- Subscribe to input events
- Respond in event handlers
- Disable controls when done
Full Transcript
The Unity New Input System works by creating input actions and generating a C# class to manage them. You instantiate this class and enable it to start listening for inputs. Then, you subscribe to specific input events like Jump. When the player presses the jump button, the Jump method runs. Finally, you disable the input actions when no longer needed to stop listening. This flow ensures clean and responsive input handling.