Null Reference Exception For An Unknown Reason
I am currently making my first game on Unity. I haven't been having any major problems so far until I tried to make a pause button. In a different scene I accessed the text of a button by declaring it as a public variable and I had no problems. In the scene for one of my levels I tried to do the same thing with the text of the pause button and I got a null reference exception. I know the text is assigned to the script but it still gives me the error, "NullReferenceException: Object reference not set to an instance of an object PlayerController.Pause () (at Assets/Scripts/PlayerController.cs:268) UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:153) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:634) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent.cs:769) UnityEngine.Events.UnityEvent.Invoke () (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:53) UnityEngine.UI.Button.Press () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:52) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:269) UnityEngine.EventSystems.EventSystem:Update()" I don't know what the problem is. I am simply trying to compare the text of the button to the string "Pause" with the code: if (pauseText.text == "Pause).
Edit your text to have paragraphs and put code into "code blocks", by selecting code text, then clicking on 101010 button on the pannel
Your answer
Follow this Question
Related Questions
Null Reference in UnityStandardAssets.Utility.WaypointProgressTracker.Update 0 Answers
Not sure why i'm getting NullReferenceException 0 Answers
There's an issue with this script I can't find 0 Answers
Random Chance NullReferenceException: Object reference not set to an instance of an object 2 Answers