EDITユニティ - C# - とNullReferenceException:オブジェクト参照がオブジェクトインスタンスに設定されていません
私の質問が異なっている(と思う...)最後の画像は、通信メッセージにゲームオブジェクトを設定するために私ができるため、コミュニケーションメッセージ。再生中は、すぐにNone(Text)とNone(Button)にリセットされます。私はなぜこれが起こるか、またはこれを解決する方法を知らない!
私はこの質問が広くカバーされているが、まだ解決できないと思います。誰かが私のための解決策を持っていることを願っています
私は行動デザイナー、Unityのための資産で働いています
をが何をしています。私は行動ツリーを作っていて、behavior tree referenceを使用しているときに問題が発生しました。
それは、フロントドアを検索:
まず、私はこのような私の行動のツリーを持っていました。それが見つかると、それはそれに向かって移動し、ゲームをプレイしている人間と通信します。
これは、前を働いていたが、今、私はこのように、行動ツリー参考に、この動作の木を置く:私は参照、最初の画像のショーをダブルクリックすると
。しかし、それは間違ってどこに行くか、これは次のとおりです。
問題
これは最初の画像における人間の命令ノードです。通信メッセージと通信ボタンはロードされません。対応するボタンをロードすると、シナリオの再生時に即座にリセットされます。 これは、ビヘイビアツリーリファレンスにこのビヘイビアをロードしたときに発生し、元のツリーのセルからこれを再生したときに問題は発生しませんでした。
NullReferenceException: Object reference not set to an instance of an object
HumanInstructions.CommunicationElements (Boolean activeOrNot) (at Assets/HumanInstructions.cs:54)
HumanInstructions.OnAwake() (at Assets/HumanInstructions.cs:19)
BehaviorDesigner.Runtime.BehaviorManager.EnableBehavior (BehaviorDesigner.Runtime.Behavior behavior)
BehaviorDesigner.Runtime.Behavior.EnableBehavior()
BehaviorDesigner.Runtime.Behavior.Start()
どのような原因が考えられ、これを解決するにはどうすればよいですか?
HumanInstructions
using UnityEngine;
using UnityEngine.UI;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks;
using UnityStandardAssets.Characters.FirstPerson;
public class HumanInstructions : Action
{
public string humanInstructionsText; // The string in inspector that shows up on-screen for the human operator to communicate with UGV.
public string messageToConsole; // Print this message to console when the action is performed SUCCESSFUL.
public string textOnButton; // See inspector in Behavior Designer. Is used as text on button.
public Text CommunicationMessage;
public Button CommunicationButton;
bool boolClicked; // Is false; when the button is clicked, it will turn TRUE, calling the IF function, returning Taskstatus SUCCESS.
public override void OnAwake()
{
CommunicationElements (false);
}
public override void OnStart()
{
boolClicked = false;
CommunicationElements (false);
CommunicationButton.onClick.AddListener (ButtonClicked);
}
public override TaskStatus OnUpdate()
{
CommunicationMessage.text = humanInstructionsText;
CommunicationButton.GetComponentInChildren<Text>().text = textOnButton;
CommunicationElements (true); // The communication elements are VISIBLE on screen.
TriggerStatusCameraView (false);
if (boolClicked == true) { // this IF function is active when the button is clicked. See ButtonClicked() function.
CommunicationElements (false); // Removes the communication elements from screen.
TriggerStatusCameraView (true);
return TaskStatus.Success;
} else {
return TaskStatus.Running;
}
}
// The following function is called when the CommunicationButton is clicked on screen.
void ButtonClicked()
{
boolClicked = true; // Changes the value to true, so it will trigger the IF function in OnUpdate();
Debug.Log (messageToConsole); // Sends this message to the console.
}
// The following function can be called upon and turn all UI elements (such as text, buttons or images) ACTIVE or not.
void CommunicationElements (bool activeOrNot)
{
CommunicationButton.gameObject.SetActive (activeOrNot);
CommunicationMessage.gameObject.SetActive (activeOrNot);
}
// The following code will DISABLE camera control if the communication screen is active for the human operator
void TriggerStatusCameraView(bool activeOrNot)
{
GameObject.Find ("FPSController").GetComponent<RigidbodyFirstPersonController_custom>().enabled = activeOrNot;
}
}
プレハブを作成してそのメンバーをシーンオブジェクトに参照し、そのプレハブからインスタンス化しようとすると、参照リンクが壊れてしまいます。多分これに関連する何か – Bijan