Search Unity

UnityEvent<T1> will be ever serialized?

Discussion in 'UGUI & TextMesh Pro' started by Breyer, Aug 22, 2014.

  1. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    As above. This would be really helpfull in some case. On front-end inspector should find all method or field with T1 in param/type but, unlike standard UnityEvent, hide field parameter in inspector (last input field in inline element of delegate list) since parameter is feeded in code instead of in inspector
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, because of restrictions in Unity core we can't serialize generics. But you can do this:

    Code (csharp):
    1.  
    2. [Serializable]
    3.  public class ButtonClickedEvent : UnityEvent <string>{ }
    4.  
    This will allow binding to string functions and the argument that is passed will be the one that is used for the 'invoke' call.
     
    Trost_, TreyH, Eldoir and 4 others like this.
  3. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    i know, however List<T> is supported? So there is chance for support in future?

    your example is good enough though

    Edit:

    I tested it recently it work but i saw input for parameter isnt blocked and no constraint to method with string only - thats why i ask for support out of the box
     
    Last edited: Aug 22, 2014
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Hi, because of restrictions in Unity core we can't serialize generics. But you can do this:

    Code (csharp):
    1.  
    2. [Serializable]
    3.  public class ButtonClickedEvent : UnityEvent <string>{ }
    4.  
    This will allow binding to string functions and the argument that is passed will be the one that is used for the 'invoke' call.
     
    DanneSS likes this.
  5. Breyer

    Breyer

    Joined:
    Nov 10, 2012
    Posts:
    412
    @Tim C

    eee what S*** happen? :eek: here and there spam...:D