unity runtime_error ai_generated true

InvalidOperationException: InputAction 'Player/Move' is not enabled. Cannot read value.

ID: unity/input-system-action-not-found

Also available as: JSON · Markdown · 中文
92%Fix Rate
88%Confidence
1Evidence
2023-09-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2022.3 active
Unity 2023.1 active
Unity 2021.3 active
Input System 1.6.0 active

Root Cause

An InputAction is being read via ReadValue() before it has been enabled (e.g., before InputSystem.EnableDevice or action map activation).

generic

中文

在 InputAction 启用之前(例如在 InputSystem.EnableDevice 或操作映射激活之前)通过 ReadValue() 读取该操作。

Official Documentation

https://docs.unity3d.com/Packages/[email protected]/manual/Actions.html

Workarounds

  1. 90% success Enable the action map before reading values: `InputActionMap actionMap = inputActions.FindActionMap("Player"); actionMap.Enable();` then call `inputActions.FindAction("Move").ReadValue<Vector2>();`
    Enable the action map before reading values: `InputActionMap actionMap = inputActions.FindActionMap("Player"); actionMap.Enable();` then call `inputActions.FindAction("Move").ReadValue<Vector2>();`
  2. 95% success Use event-based callbacks instead of polling: `inputActions.Player.Move.performed += ctx => { Vector2 value = ctx.ReadValue<Vector2>(); };`
    Use event-based callbacks instead of polling: `inputActions.Player.Move.performed += ctx => { Vector2 value = ctx.ReadValue<Vector2>(); };`
  3. 85% success Delay the first read until after InputSystem.Update() by checking `InputSystem.isInitialized` and using a coroutine.
    Delay the first read until after InputSystem.Update() by checking `InputSystem.isInitialized` and using a coroutine.

中文步骤

  1. Enable the action map before reading values: `InputActionMap actionMap = inputActions.FindActionMap("Player"); actionMap.Enable();` then call `inputActions.FindAction("Move").ReadValue<Vector2>();`
  2. Use event-based callbacks instead of polling: `inputActions.Player.Move.performed += ctx => { Vector2 value = ctx.ReadValue<Vector2>(); };`
  3. Delay the first read until after InputSystem.Update() by checking `InputSystem.isInitialized` and using a coroutine.

Dead Ends

Common approaches that don't work:

  1. 30% fail

    Calling Enable() on the action inside Start() or Awake() may still fail if the InputSystem hasn't initialized yet.

  2. 50% fail

    Disabling and re-enabling the action map in Update() causes repeated overhead and doesn't fix timing.

  3. 60% fail

    Using InputAction.ReadValue<float>() without checking isPressed first can still throw if not enabled.