- Home /
How to serialize an array of classes
Hello,
I'd like to expose an array of class in the Inspector. I'm trying to create a list of waves, each entry is a wave with different variables set. So i created a waveVO. Just a class the extends Object with some public variables.
How can i create a resizable list in the inspector where you can fill out each value of an entry?
Answer by Dreamblur · Jun 23, 2011 at 11:55 PM
The Inspector already does that automatically. Just declare your array of classes and serialize it (either by making it public or using SerializeField).
this doesn't work: [SerializeField] private NavyVO[] NavyValueObject
That should work. $$anonymous$$ake sure that you put [System.Serializable] on top of the script after the namespaces, that the array is not being declared as static, const or readonly, and that there are no error logs in the Debug console.
This is probably some nuance of Serialization I'm not aware of, but if I serialize an array of classes where some of those classes are null the array appears to deserialize to an array full of objects - the null references within the array being only naively constructed - anyone reading this have any idea why that might be and perhaps how to solve it?
This is VERY annoying, I too would like my null
items to remain null
upon deserialization! The stupid thing is that there isn't even a way to override the way in which data is serialized/deserialized. right?