Search Unity

UnityEvent<T> won't serialize with Inspector?

Discussion in 'Scripting' started by tstpierre_nss, Jan 18, 2015.

Thread Status:
Not open for further replies.
  1. tstpierre_nss

    tstpierre_nss

    Joined:
    Jul 3, 2012
    Posts:
    118
    Using vanilla public UnityEvent classes will work just fine through the Inspector...

    Now I want to pass some information along with it as well and doing something like:

    Code (csharp):
    1.  
    2. public UnityEvent<bool> MyInvokableEvent;
    3.  
    Will not show up in the inspector anymore. I want this to be assignable through the editor component inspector... through code this seems to work fine (the Invoke call is carrying over the <T> arg list), but this serves no use when building systems for non developers to work with.

    Is there any way to allow wiring up these methods that have arguments through the inspector?
     
  2. emayberry

    emayberry

    Joined:
    May 13, 2014
    Posts:
    1
    Hi, hopefully you've figured this out since the original posting, but for anyone else who comes across this (like I did), I found the answer here.

    The short answer is, you need to declare an event class inheriting from UnityEvent<T> and make sure it has the [Serializable] attribute, then in your script you'll have "public CustomClass MyInvokableEvent;"
     
  3. YayapipiStudio

    YayapipiStudio

    Joined:
    Feb 11, 2017
    Posts:
    9
    Nice!

    Code (CSharp):
    1. [Serializable]
    2. public class SampleEvent : UnityEvent<SampleClassj> { }
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,497
    You don't need to necro a post from 2015 to say nice. Please just hit like, that's what it's for.
     
    eses and Kurt-Dekker like this.
Thread Status:
Not open for further replies.