Search Unity

Serializing and deserializing a world ... easily?

Discussion in 'Entity Component System' started by SocialSimulator, Feb 15, 2019.

  1. SocialSimulator

    SocialSimulator

    Joined:
    Sep 19, 2017
    Posts:
    26
    Hello, everyone!

    Is there a simple-ish way to save a world and then rebuild it? At the moment I'm trying saving the data in an OOP structure, such as a set of Lists in a singleton on a gameobject. That can the be serialized and saved. Then when the game state is loaded, I am loading in the serialized OOP structure and then rebuilding the ECS structure. But it's a lot of code and faff and it takes time to run the routines.

    Is there a better way? All I could find was https://gametorrahod.com/unity-ecs-serializing-ecs-data-252231e5b16d which makes it look horrendous.

    Thank you, very much.
     
    Last edited: Feb 15, 2019
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,761
    Depends entirely on your data. It could be as simple as

    Code (CSharp):
    1. GameObject sharedComponents;
    2. using (BinaryWriter writer = new StreamBinaryWriter(path))
    3. {
    4.     SerializeUtilityHybrid.Serialize(entityManager, writer, out sharedComponents);
    5. }
    6.  
    7. using (BinaryReader reader = new StreamBinaryReader(path))
    8. {
    9.     SerializeUtilityHybrid.Deserialize(entityManager, reader, sharedComponentData);
    10. }
    It is an area I believe they want to work on and improve at some point though.
     
    andrew-lukasik likes this.