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
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).
官方文档
https://docs.unity3d.com/Packages/[email protected]/manual/Actions.html解决方案
-
Enable the action map before reading values: `InputActionMap actionMap = inputActions.FindActionMap("Player"); actionMap.Enable();` then call `inputActions.FindAction("Move").ReadValue<Vector2>();` -
Use event-based callbacks instead of polling: `inputActions.Player.Move.performed += ctx => { Vector2 value = ctx.ReadValue<Vector2>(); };` -
Delay the first read until after InputSystem.Update() by checking `InputSystem.isInitialized` and using a coroutine.
无效尝试
常见但无效的做法:
-
30% 失败
Calling Enable() on the action inside Start() or Awake() may still fail if the InputSystem hasn't initialized yet.
-
50% 失败
Disabling and re-enabling the action map in Update() causes repeated overhead and doesn't fix timing.
-
60% 失败
Using InputAction.ReadValue<float>() without checking isPressed first can still throw if not enabled.