Performance: Input action maps
Input action maps affect how quickly and efficiently user inputs are processed and responded to in the game, impacting input responsiveness and frame rate.
private InputAction jumpAction;
private InputAction interactAction;
void OnEnable() {
jumpAction.Enable();
interactAction.Enable();
jumpAction.performed += ctx => Jump();
interactAction.performed += ctx => Interact();
}
void OnDisable() {
jumpAction.Disable();
}void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Jump();
}
if (Input.GetKeyDown(KeyCode.E)) {
Interact();
}
// Multiple if checks every frame
}| Pattern | Input Polling | CPU Usage | Input Lag | Verdict |
|---|---|---|---|---|
| Polling keys every frame | High (multiple checks) | High | Higher lag due to constant checks | [X] Bad |
| Using InputAction callbacks | Low (event-driven) | Low | Minimal lag, responsive input | [OK] Good |
What is the main purpose of an Input Action Map in Unity's Input System?
Which of the following is the correct way to enable an InputActionMap named playerControls in C#?
?
Enable().Start(), Activate(), and Run() are not valid methods for InputActionMap.Given the following code snippet, what will be the output when playerControls is enabled and the player presses the jump button?
var playerControls = new PlayerInputActions();
playerControls.Player.Jump.performed += ctx => Debug.Log("Jump pressed");
playerControls.Player.Enable();
// Player presses jump buttonWhat is wrong with this code snippet that tries to disable an input action map?
var controls = new PlayerInputActions();
controls.Player.Disable();
controls.Player.performed += ctx => Debug.Log("Action performed");performed on controls.Player, which is an InputActionMap, not an InputAction.performed belong to InputActions, e.g., controls.Player.Jump.performed, not the whole map.You want to switch between two control schemes, Keyboard and Gamepad, during gameplay using input action maps. Which approach correctly handles this switch?
?
Pass the test and this pattern moves unknown