- Home /
Method not found, < Missing (Class).(Method) > on button OnClick() event
So I am barely new to Unity, but I have a great deal of experience in C#. So my question consists of a static method from a Player class that displays the deck to unity's debug console.
// Shows the deck on the unity debugging console
public static void dbgShowDeck(Player player)
{
for(int i= 0; i< player.deck.size+1; i++)
Debug.Log(player.deck[i].ToString());
}
But the problem is that unity doesn't register the dbgShowDeck method or any custom method I've made, and it does it to more than just the button entity.
I've looked around and the closest answer was the FindMissingScripts.cs from here. But it didn't solve my problem whatsoever. Does anyone know how to solve this problem?
Answer by cdrandin · Jan 22, 2015 at 10:01 AM
Taken from here You cannot assign a static method to an event trigger on onClick event.
I confirmed myself. It doesn't noticed the static method, however, when I remove the static and create it as an instance it works as normal.
It depends on the version of Unity. I use 4.6.1f and I can use static methods as events, it is tested. I think the problem is the Player Class is not inherited from $$anonymous$$onoBehavior. I have answered this, but is currently waiting to get my answer approved...
Actually its not taken from there and that wouldnt solve the problem entirely. When you click on the combobox it gives me, one that says "Player" with more under it that have only all the static methods that I made plus monobehavior's static methods. But none of the instanced methods pop up there. I assumed that only static methods were feasable. And I must also add that the YourDeck has a script in it which contains the Player.cs script.
Answer by DNRN · Jan 22, 2015 at 10:52 AM
I think it's because your Player class does not inherit from MonoBehaviour. If you let the Player class inherit from MonoBehaviour, Unity should be aware of the class, and you can use it in the editor e.g as an argument in a button event.
It does inherit $$anonymous$$onoBehaviour, thats how I was able to ask it to use a method from the scrip
Answer by Fortyseven · Dec 30, 2015 at 06:58 AM
While not directly related to your question, it's worth noting that when I had a callback with the signature of public void SendStateMessage( object o = null )
, I received the same issue, saying the method was 'missing'.
Once I changed it to a more specific type, like 'String', it worked as expected.
Your answer
![](https://koobas.hobune.stream/wayback/20220613181120im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers