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

Unity新输入系统中InputAction.CallbackContext函数未在Inspector显示

Unity新输入系统事件无法识别带InputAction.CallbackContext参数的函数

在Unity项目中配置新输入系统时,已创建Input Actions并给游戏对象挂载Player Input组件,同时附加了自定义脚本PlayerInputHandler.cs。尝试通过Unity事件绑定输入动作时,将脚本或游戏对象拖入事件槽后,可选函数列表里找不到接收InputAction.CallbackContext参数的OnMoveInput、OnJumpInput函数。

自定义脚本代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerInputHandler : MonoBehaviour
{
    void OnMoveInput(InputAction.CallbackContext context)
    {
        Debug.Log("OnMoveInput");
    }

    void OnJumpInput(InputAction.CallbackContext context)
    {
        Debug.Log("OnJumpInput");
    }
}

组件配置截图:
Player Input组件配置截图


解决方法

  • 修改函数访问权限:Unity事件面板仅识别**公共(public)**函数,默认void为私有权限,需将两个函数的访问修饰符改为public:
    public void OnMoveInput(InputAction.CallbackContext context)
    {
        Debug.Log("OnMoveInput");
    }
    
    public void OnJumpInput(InputAction.CallbackContext context)
    {
        Debug.Log("OnJumpInput");
    }
    
  • 刷新事件列表:修改脚本并保存后,回到Unity编辑器,重新点击事件槽的下拉菜单选择对象,即可看到目标函数。
  • 额外验证:确认Player Input组件的Behavior设置为Invoke Unity Events(截图中已正确配置);Input Actions的动作类型(如移动为Value、跳跃为Button)均可适配InputAction.CallbackContext参数,无需额外调整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 17:35:05