unity runtime_error ai_generated true

InvalidOperationException:InputAction 'Player/Move' 未启用。无法读取值。

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

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

其他格式: JSON · Markdown 中文 · English
92%修复率
88%置信度
1证据数
2023-09-01首次发现

版本兼容性

版本状态引入弃用备注
Unity 2022.3 active
Unity 2023.1 active
Unity 2021.3 active
Input System 1.6.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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.

无效尝试

常见但无效的做法:

  1. 30% 失败

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

  2. 50% 失败

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

  3. 60% 失败

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