- Home /
Serializable class definition in base class doesn't show in editor
Generic.cs
public class Generic<T> : MonoBehaviour {
public GenericEvent OnGenericEvent;
[Serializable]
public class GenericEvent : UnityEvent<T> {
}
}
MyClass.cs
public class MyClass : Generic<MyOtherClass> {
}
OnGenericEvent doesn't show in Editor, is this a bug?
Comment
Unity is not able to serialize generic classes. You need to define a concrete type for T when deriving from it.
Okay, thanks. I'll have to find other ways then
I got it working. Editor is able to serialise generic classes, but it has to be inside the class not base class.
public class GenericTrigger<T> : $$anonymous$$onoBehaviour {
public abstract class GenericTriggerEvent : UnityEvent<T> {
}
}
public class $$anonymous$$yTrigger : GenericTrigger<Class> {
public $$anonymous$$yEvent Event;
[Serializable]
public class $$anonymous$$yEvent : GenericTriggerEvent {
}
}
Answer by studioAdam · Nov 20, 2016 at 09:00 PM
I have "using System;" at top. I didn't include all coding
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Object from list in scriptableobject in list 0 Answers
How to define a slider on script file? 1 Answer
How to make buttons have sound when it is highlighted and clicked? 0 Answers