Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Invoking UnityEvent with argument

Discussion in 'UGUI & TextMesh Pro' started by Percy-Tse, Nov 28, 2014.

  1. Percy-Tse

    Percy-Tse

    Joined:
    Aug 22, 2014
    Posts:
    10
    Hi,

    I have declared a custom event by:
    Code (csharp):
    1.  
    2. // Class declaration
    3. [System.Serializable]
    4. public class MyEvent : UnityEvent<int> {}
    5.  
    6.  
    7. // Somewhere in a component
    8. // Declare
    9. public MyEvent PressEvent;
    10.  
    11. // Invoke
    12. int someValue = 123;
    13. PressEvent.Invoke(someValue);
    14.  
    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.
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,160
    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.
     
    dijek, kurohuku, lassade and 13 others like this.
  3. Percy-Tse

    Percy-Tse

    Joined:
    Aug 22, 2014
    Posts:
    10
    Thanks Tim. I found it.

    For more information, the static/dynamic option appears when selecting function.
    callback.jpg
     
    Dunk86, dijek, flchaux and 11 others like this.
unityunity