Hi, I want to make simple send message interface, something like new unity gui button will have:

Is it possible to make something like when I assign object with some script on it I’ll get list of methods in this script?
need more information of what you’re expecting.
For example I have a script RunMethod:
if(Input.GetKey(KeyCode.E))
{
//Do something
}
And I need inspector staff like this, for target to see target’s script, and its public methods to make it run if if(Input.GetKey(KeyCode.E))
![]()
It’s a fairly involved process, but you’ll want to look up the System.Reflection class in Mono. You can feed that class a type, and it can give you back lists of fields, properties, etc.
I think Unity uses reflection for this functionality. Have a look into: Type.GetMethods Methode (System) | Microsoft Learn
On one side you’re going to need a way to trap the events you want to forward.
On the other side you’ll need the object that receives the message.
You’ll need an inspector that then displays visually how those to join.
Reflection is your answer to listing out all the methods available on a class. But that’s probably the smallest part of your design here.
Your only real question though is:
Yes, it is possible.
You wanna know how? Well, it’s going to be a lot of work.
First step in designing it is describing very precisely the problem you want to solve, what you expect as an answer, and then start figuring out what’s in between. Critical thing though is knowing what the problem is, you need somewhere to start. And if your posts say anything… you haven’t described your problem, you only know the result you want.
If people think it’s an interesting feature, it will take me a few hours to add it to my assets (Advanced Inspector). ![]()
Unity doesn’t allow serialization of delegate, so you’ll probably need to save the name of the type/method in string. I assume if a GameObject has two component of the same type, you don’t have the choice between the two. Most likely in Unity’s case, they just use SendMessage, which could conflict if multiple type implement the same method.
I saw in video of 4.6 that it also has some option for passing argument to the invoked method. From the library, looks like it’s currently limited to some specific type and to 4 arguments at most.
As for listing the method;
myInstance.GetType().GetMethods();
Which returns a collection of MethodInfo.
its not built in but its also not impossible:
http://forum.unity3d.com/threads/245248-uFAction-A-complete-set-of-serializable-and-inspectable-delegates-for-Unity3D!
Lot of things are not “built-in”… Like copy/pasting field in the Inspector. ![]()
But while it’s “possible” to serialize delegate, it won’t be directly with Unity’s serialization.