unity
runtime_error
ai_generated
true
无效操作异常:无法启用操作映射'Gameplay',因为它已经启用
InvalidOperationException: Cannot enable action map 'Gameplay' because it is already enabled
ID: unity/input-system-action-map-conflict
93%修复率
87%置信度
1证据数
2023-11-05首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 1.5.0 | active | — | — | — |
| 1.6.0 | active | — | — | — |
| 1.4.4 | active | — | — | — |
根因分析
在未先禁用的情況下对已启用的InputActionMap调用Enable(),导致状态冲突。
English
Calling Enable() on an InputActionMap that is already enabled without first disabling it, causing a state conflict.
官方文档
https://docs.unity3d.com/Packages/[email protected]/manual/ActionMaps.html解决方案
-
Check if action map is already enabled before enabling: if (!inputActionAsset.FindActionMap("Gameplay").enabled) { inputActionAsset.FindActionMap("Gameplay").Enable(); } -
Use a flag to track state: private bool gameplayEnabled; void EnableGameplay() { if (!gameplayEnabled) { inputActionAsset.FindActionMap("Gameplay").Enable(); gameplayEnabled = true; } }
无效尝试
常见但无效的做法:
-
Calling Enable() multiple times in Update() without check
90% 失败
Repeats the same error; no guard against double-enable.
-
Disabling and re-enabling in same frame
50% 失败
If not properly sequenced, still throws error; better to check enabled state.