简体   繁体   English

Unity c# 中的操作图的定义变量出错(使用输入系统)

[英]Error with a defined variable for an actionmap in Unity c# (using the InputSystem)

I'm having this problem I can't figure out that involves Unity's InputSystem.我遇到了这个问题,我不知道这涉及到 Unity 的 InputSystem。 I was wondering if anyone had a solution.我想知道是否有人有解决方案。 So basically I have a script, Player, that handles most of my input system stuff with the action map.所以基本上我有一个脚本,播放器,它通过操作 map 处理我的大部分输入系统内容。 However, there's a few instances where I have to use a different script and I get odd bugs.但是,在某些情况下,我必须使用不同的脚本并且会遇到奇怪的错误。

Sp Player has this (among other code): Sp Player 有这个(以及其他代码):

public PlayerControls playerControls { get; private set; }

public void OnEnable()
{

    playerControls.Enable();
}

public void OnDisable()
{

    playerControls.Disable();

}


public void Awake()
{

    playerControls = new PlayerControls();

}

There there's a script currently that goes on objects that the player can use an interact button with, which has this:目前有一个脚本可以处理玩家可以使用交互按钮的对象,其中包含:

public PlayerControls playerControls;

Debug.Log("heroScript variable in ObjectInteraction is set to " + heroScript);
playerControls = heroScript.playerControls;

Debug.Log("playerControls is " + playerControls.ToString());
playerControls.PlayerActions.Interact.performed += InteractWithObject;

The two images have the error readout I get on play as well as what is assigned in the script in unity.这两个图像具有我在播放时得到的错误读数以及脚本中统一分配的内容。

Bug readout错误读数

Script field on the object it is on object 上的脚本字段

I've gone in circles trying to fix this and I'm not sure what I am doing wrong, you can see that the debug.log finds the value of the variable, but I'm still erroring out when it is being set.我一直在试图解决这个问题,但我不确定我做错了什么,你可以看到 debug.log 找到了变量的值,但是在设置它时我仍然出错。

Also, line 69 is此外,第 69 行是

playerControls = heroScript.playerControls;

For those that are having the same issue that stumble on this, it seems like you do have to run everything through a "parent" script that is the one that declares the action map with the line:对于那些遇到同样问题的人来说,似乎您确实必须通过“父”脚本运行所有内容,该脚本使用以下行声明操作 map:

yourActionMapVariableHere = new YourActionMapNameHere();

Any other scripts that need to use the action map will have to be filtered through that primary script.需要使用操作 map 的任何其他脚本都必须通过该主脚本进行过滤。 The people that have helped me that are familiar with the InputSystem in Unity have not been able to give me an answer on a way to do otherwise, and I am pretty sure you don't want to generate multiple versions of the same action map, though I do not actually know what the consequences of that could be.帮助过我熟悉 Unity 中的 InputSystem 的人无法就其他方式给我答案,我很确定您不想生成同一操作 map 的多个版本,虽然我实际上并不知道这样做的后果是什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM