Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Object reference not set to an instance of an object

i would like some help on this error:

NullReferenceException: Object reference not set to an instance of an object

NameTransfer.Update () (at Assets/NameTransfer.cs:15)

UnityEngine.Events.InvokableCall.Invoke () (at <9674024ab0e74d27bbe9eaa30dab34d1>:0)

UnityEngine.Events.UnityEvent.Invoke () (at <9674024ab0e74d27bbe9eaa30dab34d1>:0)

UnityEngine.UI.Button.Press () (at C:/Program Files/Unity/Hub/Editor/2019.4.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:68)

UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.4.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Button.cs:110)

UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.4.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)

UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2019.4.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)

UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.4.14f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)



This is my c# code:

using UnityEngine;

using UnityEngine.UI;


public class NameTransfer : MonoBehaviour

{

   public string nameOfUser; // typed name by the user

   public GameObject inputField;

   public GameObject textDisplay;



   public void Update()

   {

       nameOfUser = inputField.GetComponent<Text>().text;

       textDisplay.GetComponent<Text>().text = "Welcome " + nameOfUser + "to the Soil Mechanics Laboratory game!";


   }




}


Sign In or Register to comment.