unity runtime_error ai_generated true

InvalidOperationException: Cannot enable action map 'Gameplay' because it is already enabled

ID: unity/input-system-action-map-conflict

Also available as: JSON · Markdown · 中文
93%Fix Rate
87%Confidence
1Evidence
2023-11-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1.5.0 active
1.6.0 active
1.4.4 active

Root Cause

Calling Enable() on an InputActionMap that is already enabled without first disabling it, causing a state conflict.

generic

中文

在未先禁用的情況下对已启用的InputActionMap调用Enable(),导致状态冲突。

Official Documentation

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

Workarounds

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

中文步骤

  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; } }

Dead Ends

Common approaches that don't work:

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

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

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

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