- Home /
Custom Inspector - Method Selector just like Button OnClick()?
What would be the easiest way to implement a method selector just like the UI Button's OnClick()? So I can drag in a GameObject, select a script, and a method/variable? Would I have to completely write it from scratch, or is there any sort of helpers?
Answer by troien · Nov 29, 2015 at 07:56 PM
There is no need for a custom inspector here, you can simply use the UnityEvent class. Note that it is inside the 'UnityEngine.Events' namespace, so (in C#) make sure you put 'using UnityEngine.Events' at the top.
If you want to use parameter(s), see UnityEvent<T>, UnityEvent<T0,T1> etc.
As for how to use these classes, check the examples in the links.
EDIT:
Forgot to mention, if you use it, but can't edit it inside the inspector (like in some examples), make sure you make the classes that inherrit from UnityEvent "[Serializable]". This is what Unity does with the ButtonClickedEvent ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220612050748im_/https://answers.unity.com/themes/thub/images/avi.jpg)