Invoking UnityEvent with argument

Hi,

I have declared a custom event by:

// Class declaration
[System.Serializable]
public class MyEvent : UnityEvent<int> {}


// Somewhere in a component
// Declare
public MyEvent PressEvent;

// Invoke
int someValue = 123;
PressEvent.Invoke(someValue);

When Invoke is called, the argument received by callback function is always equals to the value showing in inspector.
Is there any way to invoke with dynamic arguments?
Thanks.

6 Likes

HI. In the inspector for the element you will notice there are two sections. Static and Dynamic. Dynamic calls use the value from the invoke, and static use the value you have manually set. You need to point to the dynamic call for this to work.

32 Likes

Thanks Tim. I found it.

For more information, the static/dynamic option appears when selecting function.
1866855--119873--callback.jpg

25 Likes

thanks! i wondering about this problem in several days

This worked, thanks a lot!