Hi,
how can I get the arguments passed by a UnityEvent (which I set in the Inspector) at runtime?
So far I can get the target component and the method that is going to be called, but how can I get the argument I set?
Cheers,
Wavy
Hi,
how can I get the arguments passed by a UnityEvent (which I set in the Inspector) at runtime?
So far I can get the target component and the method that is going to be called, but how can I get the argument I set?
Cheers,
Wavy
Declare proper function parameter.
That doesn’t answer my question.
And I do:
protected void DoStuffWithEvent(UnityEvent e)
{
var eventCount = e.GetPersistentEventCount();
for (int i = 0; i < eventCount; i++)
{
var target = e.GetPersistentTarget(i);
var method = e.GetPersistentMethodName(i);
}
}
So how do I get the Boolean and the string for both actions?
You want boolean, but declared UnityEvent argument.
No, I want to get the setting that I defined in the Inspector for the UnityEvent.
I can get the targets and the methods of the registered persistent event listeners, but I can’t get the argument that is passed. Can I get it via Reflection?
I’m not asking how to write a Listener method.
Dig into m_Calls, m_PersistentCalls. There should be objects of type PersitantCall or alike, it has private field of type ArgumentCache, i suppose it’s there. But you can’t get unity event instance you’re handling inside handler, only argument value.