Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Saving/Loading runtime world state

Discussion in 'Entity Component System' started by e199, Mar 13, 2019.

  1. e199

    e199

    Joined:
    Mar 24, 2015
    Posts:
    101
    Hi, with entity scenes getting more user friendly I was thinking about the way to save/load runtime world state

    What I mean by that is there should be a method to
    - store all entities/components(non shared) of world into byte array
    - read array and place data into memory for that world

    One of reasons for it is debugging. Imagine opening bug ticket from QA and just load corrupted state
    - Or desync detection for deterministic sim, each client calculates hash for that byte array and send number of that frame and hash to all others or server
    - Or send that byte array as the correct state for further deterministic sim
     
  2. ilih

    ilih

    Joined:
    Aug 6, 2013
    Posts:
    1,402
    SerializeUtility and SerializeUtilityHybrid classes in Unity.Entities.Serialization namespace.
    But you can save/load only files with StreamBinaryWriter and StreamBinaryReader (ignore Stream in the name, they work with files) or you can create custom reader/writer to work with byte array implementing BinaryReader/BinaryWriter interface.