Search Unity

Feature Request Unity Event List/Array

Discussion in 'Editor & General Support' started by guluerechan, Oct 28, 2022.

  1. guluerechan

    guluerechan

    Joined:
    Mar 24, 2022
    Posts:
    9
    In unity, using Unity Event would create a function call similar to button-pressing calls. It has been a great tool for me to use more effectively to build a game.

    I am trying to make it into a list or array so I can better put them side to side and do certain things with them involving loops. But because Unity Event is Serializable by nature, they get turned into displaying their variables instead of showing the button-ish display.

    Want to know if there is any way to partially unserialize it, because of System.NonSerialized just hides it.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    It's not a serialisation issue, but a custom inspector issue. UnityEvent and it's derived types will have a custom inspector that draw it normally looks when as a field, but I suppose this doesn't work when nested in an array? Not entirely surprising given Unity's very non-modular approach to inspectors.

    I'd almost consider this a bug, but then again fields like the Addressables asset reference fields also screw up when nested in any way, so it's not unusual.
     
  3. guluerechan

    guluerechan

    Joined:
    Mar 24, 2022
    Posts:
    9
    I see, I just assumed it was a matter of the serialization because usually that reduces things down into their variables.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    You have your terms mixed up. Serialisation is how values are written and read to and from disk, which is separate to how said values are drawn. When you select an asset, Unity deserialises it, then works out the appropriate property drawer for each given type, then draws said types (over simplification, but basically how it works).

    So basically with Unity sees a class of type UnityEvent, it gets the appropriate drawer and uses that to draw it in the inspector (instead of the strings and object references that is is under the hood). It seems this doesn't work when nested in a collection.
     
  5. lacas8282

    lacas8282

    Joined:
    Apr 25, 2015
    Posts:
    139
    Any news in this? Workaround?