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

其他格式: JSON · Markdown 中文 · English
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.

generic

官方文档

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

解决方案

  1. Check if action map is already enabled before enabling: if (!inputActionAsset.FindActionMap("Gameplay").enabled) { inputActionAsset.FindActionMap("Gameplay").Enable(); }
  2. Use a flag to track state: private bool gameplayEnabled; void EnableGameplay() { if (!gameplayEnabled) { inputActionAsset.FindActionMap("Gameplay").Enable(); gameplayEnabled = true; } }

无效尝试

常见但无效的做法:

  1. Calling Enable() multiple times in Update() without check 90% 失败

    Repeats the same error; no guard against double-enable.

  2. Disabling and re-enabling in same frame 50% 失败

    If not properly sequenced, still throws error; better to check enabled state.