How to get button shown in the inspector for method on scriptable with using attribute

Hi! I was trying to figure out how to have button shown in the inspector that will trigger method
in the scriptable object like this

[Button]
public void Populate()
{

}

so, I have a scriptable object, named Storage. I create instance of it in editor time. I have a few methods that I currently trigger via context menu that I want now just to mark with attribute like this [Button] and to have it shown in the inspector. I suspect that I need to have atrribute class and custom property drawer but I am not sure how to get the method to trigger?

This is the most simplest case that I can’t figure out, can somebody point me in the right direction or share samples.

Thanks!

1 Like

Any idea how to do this? it’s for learning purposes…
I know I need to get the button attribute class that will be used on some method and property drawer, but how to get
the method to invoke? I should be using reflection, but don’t know how to connect it all

I just have the same question for a longtime, until I find this perfect solution:
https://github.com/dbrizov/NaughtyAttributes

Not only you can create Button Attribute to Invoke Method, but also ReorderableList, Dropdown, Preview and so on!

4 Likes