Is there any way to use a System.Object class in a class which extends ScriptableObject for use in AssetDatabase.CreateAsset? Try as I might, unity does not want to serialize the System.Object and anything with an System.Object type gets thrown away on serialization.
All classes inherit from
You can certainly create a class which inherits directly from
Ignoring questions of namespace and scope, an object can certainly contain references to objects of any other type. That says nothing about whether or not those references will be serialized, of course, which seems to be what you're after.
I've had some luck getting Unity to serialize custom classes like so:
I assume it's possible to do more than that, but I haven't had many chances to explore this in depth. ;)
One important caveat with Unity serialization: it is not polymorphic. If the list you're serializing has mixed types, Unity will serialize every node as the list's generic type.
In my experience, this is one of the trickier topics with Unity dev. You're sort of "going off the map".
answered Apr 12 '12 at 06:59 PM
Thanks for the response. If I explicitly strongly type my fields, such as a data type containing strings and ints etc. Unity happily serializes everything, and I can perform an AssetDatabase.CreateAsset, and LoadAssetAtPath to restore that object later. Unfortunately, this topic isn't quite so simple. I am using reflection to pull the data out of all public properties of a script which extends monobehaviour at runtime, so it has to be absolutely dynamic, as there is no telling what public properties the other developers will add. Hence I must create an array of name value pairs, and the value has to be an object. What is weirder, is that Unity will chug along just fine on datatypes that are not an object, it absolutely will not serialize something with a data type of object.