GameObjectSerialization.txt 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. TODO
  2. - Ability to break external references as a pre-processing step
  3. ---------------------------------------
  4. C# component serialization
  5. Over the weekend
  6. - Figure out how to serialize C# Components
  7. - And generic non-component serializable types
  8. Will I need to break references to non-game object and non-resource elements when serializing?
  9. - Well those should be ignored from serialization in the first place somehow
  10. - Even for Undo/Redo because those values aren't persistent and dont need to be restored upon undo
  11. Ignoring serialization, how will I create custom Components in C# in the first place?
  12. - Every custom Component derives from Component, which creates "ScriptComponent" in C++
  13. - ScriptComponent has access to ScriptComponentRTTI (or more generic SerializableObjectRTTI), which is described further below
  14. RuntimeScriptObjects
  15. - enumerateAll()
  16. - Goes through all (non-C++) Components in C#
  17. - For each it creates ScriptComponentRTTI
  18. - Finds all its fields using reflection
  19. - Only includes value type fields, structures marked with [Serializable], references to other Components, SceneObjects or Resources
  20. - Considers attributes
  21. - [Serialized] - Forces field to be serialized (If valid type)
  22. - [NotSerialized] - Forced field not to be serialized
  23. - By default all public members are serialized and private ones are not
  24. - Goes through all non-Component classes marked with [Serializable]
  25. - For each it creates ScriptSerializableStructureRTTI
  26. - Find all its fields using reflection
  27. - Only references value type fields, or fields holding other [Serializable] structures
  28. - Plus arrays, and possibly C# List
  29. - Considers attributes
  30. - [Serialized] - Forces field to be serialized (If valid type)
  31. - [NotSerialized] - Forced field not to be serialized
  32. - By default all public members are serialized and private ones are not
  33. ScriptComponentRTTI
  34. - Need to override all field getters from RTTIType so it can deal with fields dynamically
  35. - Returned type name is exact name extracted from C# code.
  36. - What about type id?
  37. - How do I ensure type ids are consistent between enumerateAll calls? (Possibly even different projects like with Unity)
  38. - Somehow replace type id with actual type name + namespace? - HOW? TODO
  39. - How do I ensure different versions of the same Component serialize properly?
  40. - e.g. I add or remove a field from Component, which requires recompilation and I have no way of ensuring field IDs will match the previous version
  41. - Somehow replace field ids with actual field names? HOW? TODO
  42. SOLUTION: Make C# serialization a layer on top of the current system, so I don't need to change the current system
  43. - This solves three of the problems above:
  44. - I don't need to modify RTTIType so I can override its field methods
  45. - And I can use field and class/namespace names instead of type IDs
  46. - ScriptComponentRTTI contains just a few static fields:
  47. - C# class name
  48. - C# namespace name
  49. - C# list of field names, field types and their values
  50. - (Although I might want to move this functionality outside of ScriptComponentRTTI and make it more generic)
  51. Unity also has a way of saving generic ScriptObjects. They serialize the same as Components.
  52. - Make a SerializableObject class that both Component and custom assets may derive from. Then it can use the same exact functionality.
  53. When I reference other C# Components I can't just use GameObject ID, since I cannot deduce the managed reference from that.
  54. - In C++ store a dictionary with a mapping from all GameObjects (Maps from ID to Managed object)
  55. - POTENTIALLY I can use that mapping for ALL managed objects?