unity runtime_error ai_generated true

InvalidOperationException: Cannot rebind action 'Jump' because the control 'Keyboard/space' is already bound to action 'Fire' in the same map

ID: unity/input-system-usage-conflict

Also available as: JSON · Markdown · 中文
90%Fix Rate
87%Confidence
1Evidence
2024-03-05First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2022.3 active — — —
Unity 2023.1 active — — —
Input System 1.7.0 active — — —

Root Cause

Two actions in the same Input Action Map share the same binding path, causing a conflict during runtime rebinding.

generic

中文

同一输入动作映射中的两个动作共享相同的绑定路径,在运行时重新绑定时导致冲突。

Official Documentation

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

Workarounds

  1. 90% success Open the Input Action Asset in the editor, select the 'Fire' action, and change its binding path to a different key (e.g., 'Mouse/leftButton'). Then rebind 'Jump' to 'Keyboard/space'. Alternatively, use composite bindings like '1D Axis' to share controls with modifiers.
    Open the Input Action Asset in the editor, select the 'Fire' action, and change its binding path to a different key (e.g., 'Mouse/leftButton'). Then rebind 'Jump' to 'Keyboard/space'. Alternatively, use composite bindings like '1D Axis' to share controls with modifiers.
  2. 85% success In code, before rebinding, check for conflicts using InputActionRebindingExtensions.GetBindingIndexForControl and manually unbind the conflicting action. Example: var rebind = action.ApplyBindingOverride(newBindingPath, conflicts: InputBinding.MaskByGroup("Keyboard"));
    In code, before rebinding, check for conflicts using InputActionRebindingExtensions.GetBindingIndexForControl and manually unbind the conflicting action. Example: var rebind = action.ApplyBindingOverride(newBindingPath, conflicts: InputBinding.MaskByGroup("Keyboard"));

中文步骤

  1. Open the Input Action Asset in the editor, select the 'Fire' action, and change its binding path to a different key (e.g., 'Mouse/leftButton'). Then rebind 'Jump' to 'Keyboard/space'. Alternatively, use composite bindings like '1D Axis' to share controls with modifiers.
  2. In code, before rebinding, check for conflicts using InputActionRebindingExtensions.GetBindingIndexForControl and manually unbind the conflicting action. Example: var rebind = action.ApplyBindingOverride(newBindingPath, conflicts: InputBinding.MaskByGroup("Keyboard"));

Dead Ends

Common approaches that don't work:

  1. 50% fail

    Disabling the conflicting action does not free the binding; the conflict persists in the asset.

  2. 30% fail

    Deleting and recreating the action map from scratch may lose all bindings and is overkill.