I am attempting to add events based on what’s read from XML, so I need reflection to access the event, the object calling the method, and the method to be called when the event fires. The actual content of the AddListener is commented above for reference of what I intend to do after this is solved. But the current code causes a null pointer at the Button.cs line 66. Normally when this appears, it further points up somewhere else that’s where the null pointer happened, but not this time. For some reason, the stack trace ends at Button.cs line 66.
And I don’t have the source the check what’s happening
This is the code that causes this:
UnityEngine.Events.UnityEvent ev = ((UnityEngine.Events.UnityEvent)member.GetMemberValue(target));
ev.AddListener(() => { });
The error:
NullReferenceException: Object reference not set to an instance of an object
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:66)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:108)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/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:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()