0
0
Unityframework~8 mins

Input action maps in Unity - Performance & Optimization

Choose your learning style9 modes available
Performance: Input action maps
MEDIUM IMPACT
Input action maps affect how quickly and efficiently user inputs are processed and responded to in the game, impacting input responsiveness and frame rate.
Handling player input with action maps
Unity
private InputAction jumpAction;
private InputAction interactAction;

void OnEnable() {
  jumpAction.Enable();
  interactAction.Enable();
  jumpAction.performed += ctx => Jump();
  interactAction.performed += ctx => Interact();
}

void OnDisable() {
  jumpAction.Disable();
}
Using InputAction callbacks avoids polling every frame and only triggers code when input occurs, reducing CPU usage and improving responsiveness.
📈 Performance GainInput processed only on events, reducing CPU usage and input lag significantly.
Handling player input with action maps
Unity
void Update() {
  if (Input.GetKeyDown(KeyCode.Space)) {
    Jump();
  }
  if (Input.GetKeyDown(KeyCode.E)) {
    Interact();
  }
  // Multiple if checks every frame
}
Checking multiple input keys manually every frame causes unnecessary CPU usage and can lead to missed inputs or lag.
📉 Performance CostTriggers input polling every frame for each key, increasing CPU load and potentially causing input lag.
Performance Comparison
PatternInput PollingCPU UsageInput LagVerdict
Polling keys every frameHigh (multiple checks)HighHigher lag due to constant checks[X] Bad
Using InputAction callbacksLow (event-driven)LowMinimal lag, responsive input[OK] Good
Rendering Pipeline
Input action maps process input events before the frame update cycle, triggering callbacks that update game state and UI accordingly.
Input Processing
Game Logic Update
Rendering
⚠️ BottleneckInput Processing stage can become expensive if polling is done inefficiently every frame.
Core Web Vital Affected
INP
Input action maps affect how quickly and efficiently user inputs are processed and responded to in the game, impacting input responsiveness and frame rate.
Optimization Tips
1Use InputAction callbacks instead of polling keys every frame.
2Enable and disable input actions properly to avoid unnecessary processing.
3Profile input handling to ensure minimal CPU usage and low input lag.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using InputAction callbacks over polling keys every frame?
AInput is processed only when an event occurs, reducing CPU usage.
BIt increases the number of input checks per frame.
CIt delays input processing until the next frame.
DIt requires more memory to store input states.
DevTools: Profiler
How to check: Open Unity Profiler, record while playing, check CPU usage under Input and Scripts sections.
What to look for: Look for high CPU time spent in input polling or Update methods indicating inefficient input handling.