Author Topic: Error: Failed to call function OnClick... Calling function with no parameters  (Read 9232 times)

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
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.

seandanger

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 2
  • Posts: 32
    • View Profile
    • Bit By Bit Studios
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!