Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: seandanger on January 09, 2013, 02:31:29 PM

Title: Error: Failed to call function OnClick... Calling function with no parameters
Post by: seandanger on January 09, 2013, 02:31:29 PM
Has anyone come across this?  I've used UIEventListener.Get to add delegates successfully so many times, all of a sudden this particular one always throws this error (even though the function does get called).

  1. public Class SomeComponent : MonoBehaviour
  2. {
  3.     void Start()
  4.     {
  5.         UIEventListener.Get(this.gameObject).onClick += OnClicked;
  6.     }
  7.  
  8.     private void OnClicked(GameObject go)
  9.     {
  10.         Debug.Log("OnClicked");
  11.     }
  12. }
  13.  

Clicking this GameObject in game will print this in the console:
Quote
Failed to call function OnClick of class SomeComponent
Calling function OnClick with no parameters but the function requires 1.

OnClicked

Everything still works but I have no idea why Unity is throwing this error.  Anyone see this before?

This thread may be relevant too: http://answers.unity3d.com/questions/55194/suggested-workaround-for-sendmessage-bug.html
Title: Re: Error: Failed to call function OnClick... Calling function with no parameters
Post by: ArenMook on January 09, 2013, 03:37:46 PM
Get rid of your Start function, and get rid of the GameObject parameter. Then rename your OnClicked function to just OnClick. Delegates are for subscribing to events that happen on remote objects. You're using it locally.
Title: Re: Error: Failed to call function OnClick... Calling function with no parameters
Post by: seandanger on January 09, 2013, 03:43:04 PM
Doh, of course. 

I normally don't add click handling code within the component itself, I usually compose my components in a different class and assign delegates there.  Stupid mistake, thanks for the help!