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 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.
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!