- Home /
Serializing data structures the Unity way. Possible?
I want to serialize some custom classes and some C# types as Dictionary
or Hashtable
. Is there any way to write on top of Unity's custom serialization system? (e.g. overriding ISerializable
)
Answer by whydoidoit · Mar 26, 2013 at 06:40 PM
Not that I've found. I serialize those types into Lists which will serialize OK and then build them back up in Awake or OnEnable. I also use my UnitySerializer to serialize custom objects to byte[] and then load them back in afterwards.
Such a pitty. How does Unity serialize List
? Do we have access/documentation on this? (e.g. Inspecting the assembly, reflecting)
I've no idea what that serialization is doing - I used to continually write Dictionary members and then remember that the didn't work when everything vanished. There's no doc I can find on the serialization stuff, you can dotPeek the source, but lots is in the C++ and we can't see that.
It's not doing normal serialization - it's doing that SerializedObject, SerializedProperty thing. I'm sure someone though that was a good idea somewhere along the way :) They must have got stuck on the complexity of serializing references to other unity gameobjects and components held in collections - it's not easy, but it's perfectly doable.
I see. Here be dragons. Any announcement on Unity's roadmap to enhance the current serialization API to support custom advanced serialization? Or is just too complex to even think about it?
Well I have a poll going for adding Level serialization including Dictionaries etc. It's doing all right. Link from here
Your answer
Follow this Question
Related Questions
Nested Dictionary data lost after playmode 0 Answers
In this case the lists do not serialize. Why? 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Combine Children Dictionary in place of Hashtable? 2 Answers