You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ArgumentException异常:已配置Input Button Interact仍提示未设置

解决Input Button "Interact"未配置的异常问题

核心原因:Starter Assets的First Person Controller默认使用新输入系统(Input System Package),而非旧的Input Manager

你在Input Manager里的配置对新输入系统完全无效,这就是报错的根源。下面是具体解决办法:


方案1:改用新输入系统(推荐,符合Starter Asset的设计)

  1. 在PlayerInput组件中添加Interact动作
    找到First Person Controller上的PlayerInput组件,打开对应的Input Action Asset(比如FirstPersonInputActions),添加一个新的Action:

    • 命名为Interact,类型选Button
    • 绑定按键:点击Binding,选择Keyboard > E
  2. 代码中通过新输入系统检测输入
    替换你当前的代码,用新输入系统的方式实现:

    using UnityEngine;
    using UnityEngine.InputSystem;
    
    public class InteractScript : MonoBehaviour
    {
        public PlayerInput playerInput;
        private InputAction interactAction;
    
        void Awake()
        {
            // 获取配置好的Interact动作
            interactAction = playerInput.actions["Interact"];
        }
    
        void OnEnable()
        {
            // 订阅按下事件
            interactAction.performed += OnInteractPressed;
        }
    
        void OnDisable()
        {
            // 取消订阅,避免内存泄漏
            interactAction.performed -= OnInteractPressed;
        }
    
        void OnInteractPressed(InputAction.CallbackContext context)
        {
            Debug.Log("Interact");
        }
    }
    

    把脚本挂到First Person Controller上,拖拽PlayerInput组件到脚本的playerInput字段即可。


方案2:强制使用旧Input Manager(不推荐,破坏Starter Asset的原生逻辑)

如果你一定要用旧的Input Manager:

  1. 打开Edit > Project Settings > Player,找到Active Input Handling,改成Input Manager (Old),然后重启Unity。
  2. 检查Starter Asset是否提供了旧输入系统的适配版本(部分Starter Asset包含切换脚本,比如SwitchInputSystem),运行脚本切换到旧输入模式。
  3. 再次确认Input Manager里的Interact是Button类型,拼写完全一致(大小写敏感),绑定的按键正确。

额外排查点

  • 检查Input Manager里的输入项:是不是把Interact创建成了Axis而不是Button?Input.GetButtonDown只识别Button类型的输入。
  • 拼写检查:确保代码里的"Interact"和Input Manager里的名称完全一致(大小写、空格都不能错)。

内容的提问来源于stack exchange,提问作者Simon Ripoll

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:37:42