- Home /
Is the class derived/inherited from generic list serializable?
 [System.Serializable]
 public class ThingList: List<Thing> {}
 
 public ThingList things;
Inspector shows label "Things" only. What's wrong?
No, it can't get serialized (not by Unity's Serializer). Anyway I'd advise to go over this, given the sort co$$anonymous$$g of the Serializer and best practices in general, it would be better to wrap the List of Things inside the ThingList class. .
Answer by LW · Sep 15, 2020 at 01:39 PM
Not sure if anyone else comes across this, at some point, but it appears Has-a relationships are serialized but Is-a relationships aren't serialized (or aren't displayed correctly).
 
 E.g.
 
 // Won't display correctly (Is-a relationship). 
 [Serializable] public class ThingList : List<Thing> {} 
 
 // Will serialize as intended (Has-a relationship).
 [Serializable] public class ThingList
 {
     public List<Thing> things;
 }
 If you implement wrappers for the interfaces ( ICollection<T>, IEnumerable<T>, IEnumerable, IList, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection, IList) and add a PropertyDrawer (that just calls it child's drawer), it should appear the same as any other generic list.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                