Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Using UnityEvent<bool> in the inspector?

Discussion in 'Scripting' started by StarManta, Dec 1, 2014.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    I've used UnityEvents to create one of those nice little inspector interfaces , into which you can drag objects and choose methods, and so on. And in the UI components (e.g. Toggle), there are variants which can take bools or floats as parameters.

    Combining the two has been fruitless so far. Having this in my code:
    Code (csharp):
    1.  
    2.     public UnityEvent<bool> onChangeState;
    3.  
    ...does not make anything appear in the inspector, unlike its non-generic, parameterless cousin.

    How can I make that show up?
     
  2. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Try something like this.

    You can't use the Generic UnityEvents directly.

    Code (CSharp):
    1. class MyEvent : UnityEvent<bool> {}
    2. public MyEvent MyEvent;
     
    Rechronicle, cLick1338 and msf-eng92 like this.
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Tried that. It compiles, but still nothing in the inspector.
     
  4. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Make your event class serializable using the [System.Serializable] attribute.
     
    CraftedGaming and msf-eng92 like this.