- Home /
IPointerClickHandler error
I was working just fine with the 4.6b17, when suddently I'm starting to get this error when I click on my buttons. They activate a method in other script passing a GameObject by parameter. If i use not my script, but some of the functions natively avaiable on OnClick event trigger, the error don't occurs.
Someone know what is this?
Error:
Type IPointerClickHandler expected Button received. i:0. Object reference not set to an instance of an object
UnityEngine.EventSystems.EventSystem:Update()
I'm getting the same error - if I can figure it out I'll let you know.
Just came across this error hope someone can go into detail what it means
Answer by Gizmoi · Sep 03, 2014 at 10:06 AM
I also received this error. It was due to a NullReferenceException being thrown in the handler I had assigned to the button.
Check that the handler you have assigned isn't thrown any exceptions or errors. Either attach the debugger and step through the code, or comment out the code inside the handler and check if it runs ok without it. That should tell you what it is.
Well, I kinda of figured out what was going here. I was getting all components of a certain type using GetComponentsInChildren, and then by accessing a child gameobject with a common name in all of them, by transform.FindChild("test").
Sometimes (my logic fault's) I was getting an object that hasn't this child, and when this occured, the error IPointerClickHandler was showed. I changed somethings and I used a validation '!= null' to avoid this. Now is working.
Unfortunately I still have no idea what was causing my issue. It seems to have resolved itself after rebuilding the scene from scratch. Luckily I didn't have much do rebuild.
@BBoldenow I still think that's a Unity 4.6 bug, because I changed nothing on my scene and started to get this issue on all my buttons. When added a new button, it worked fine. There are an issue tracker reported here: http://issuetracker.unity3d.com/issues/when-a-null-reference-occurs-on-the-button-on-click-the-thrown-exception-does-not-point-to-the-line-that-caused-the-error
Answer by purpleshirt · Sep 16, 2014 at 05:12 AM
I also got this error.
In my case I was able to use some debug calls to find out the cause. I had made a reference to an out of bounds array reference somewhere in my own code. It wasn't in the original method that the button called, but in another method called in the subsequent scripting. I only bring this up to illustrate that the error is was not immediately local to the point where the button "jumped in" so to speak.
It was a bit of a challenge because, unlike non-button related errors, the error that pops up (with the red exclamation point) doesn't reference a line number for the error. It initially made me think the button was running some kind of script that I didn't write which was throwing up an error I didn't recognize.
I suspect that this error may be thrown up any time an error occurs before the (any?) method(s) called by the button run to completion. This makes it very challenging to quickly see where the error is!
Alas, it seems it was all my fault!
I hope this helps you or anyone else who has this error turn up on them. Good luck!
Your answer
Follow this Question
Related Questions
How to access SourceImage component of a button in new GUI 4.6 1 Answer
On Click paramaters disappear from button prefab? 5 Answers
(unity 4.6) GUI stuttering during animations 1 Answer
(4.6 UI) How to set up a window with x buttons, with a scroll bar? 1 Answer
uGUI: Button that overlaps text 1 Answer