Question by
RaRdqq · Feb 28, 2019 at 06:00 PM ·
editoreditor-scriptingserializationeventeventsystem
UnityEvent with all derived types in listeners serialized in Inspector
Lets assume I have this code:
[Serializable]
public class UnityEventMessage: UnityEvent<EventMessage> { }
[Serializable]
public abstract class EventMessage {}
public class Event1:EventMessage {}
public class Event2:EventMessage {}
Now what I want is to set my UnityEvent in inspector like this:
[SerializeField] private UnityEventMessage messageCallback = new UnityEventMessage();
After that, I want my event to accept all the derived classes in params to be set inside Inspector. But it accepts only base class - EventMessage
public void TestCallback(EventMessage message) // This shows in inspector as Dynamic
public void TestCallback(Event1 message) // cant select in inspector
public void TestCallback(Event2 message) // cant select in inspector
Comment
Your answer
Follow this Question
Related Questions
UnityEvent Generic (Inspector Serialization) 0 Answers
A script behaviour has a different serialization layout... 7 Answers
Array does not serialize properly in a prefab instance for a scene 0 Answers
Information about when it is destroyed any GameObject on scene. 0 Answers
Adding EventTrigger.Entry to EventTrigger component via script doesn't update component's editor UI 0 Answers