This is the full error (in this new scenario, it is a NullReferenceException):
NullReferenceException: Object reference not set to an instance of an object
FightScript.startFight_Click () (at Assets/Scripts/FightScript.cs:105)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
Here is the code:
public void startFight_Click() // line 100
{
...
Debug.Log(strengthHeroValue.ToString()); // line 105 here
...
}
strengthHeroValue is declared at the class level as public like this:
public Text strengthHeroValue;
In the UI, strengthHeroValue is assigned to a ValueText in the FightScript (Script) section.
I have a button called startButton and in the On Click() section, I chose FightController and then FightScript.startFight_Click() event.
When I double click on the error, it brings me to the startFight_Click() method which is line 100.
Thanks for your help.
NullReferenceException? I'd be very, very surprised if it were actually the linename = "George";. Perhaps the line numbers are being messed up somehow?MonoBehaviourclass already has apublic string name;member, so yours is hiding the one from your base class. For a start, try changing younamefields name and see if things get clearer.startFight_Clicklooks like aClickevent handler on astartFightfield. If Unity is doing the event binding through reflection butstartFighthasn't been initialized, it could in theory create an unbound delegate. The call pushes null onto the stack just fine, but within the method, the ldarg.0 instruction pushes the null, and then the stfld instruction throws the exception. Try putting a breakpoint on the{and taking a look atthisandstartFightin the watch window.name = "George";is causing an error. Double-click on the error then post the correct code on the line that's causing that error