unity runtime_error ai_generated true

InvalidOperationException: 无法重新绑定动作'Jump',因为控件'Keyboard/space'已绑定到同一动作映射中的动作'Fire'

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

其他格式: JSON · Markdown 中文 · English
90%修复率
87%置信度
1证据数
2024-03-05首次发现

版本兼容性

版本状态引入弃用备注
Unity 2022.3 active
Unity 2023.1 active
Input System 1.7.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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"));

无效尝试

常见但无效的做法:

  1. 50% 失败

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

  2. 30% 失败

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