Serializing and Deserializing

I’m trying to Serialize and Deserialize a world to make a save/load system but I’m getting an error message when running DeserializeWorld and I have no idea how to fix it.

Here’s the error:
We are reading a UnityEngine.Object however no ObjectTable was provided to the PropertiesBinaryReader.

Here’s my code:

// Serialization
var file = Application.persistentDataPath + "/test-save.dat";
    
BinaryWriter writer = new StreamBinaryWriter(file);
SerializeUtility.SerializeWorld(EntityManager, writer);
writer.Dispose();

// Deserialization
var file = Application.persistentDataPath + "/test-save.dat";
var world = new World("Deserialization World");
var entityManager = world.EntityManager;
BinaryReader reader = new StreamBinaryReader(file);
SerializeUtility.DeserializeWorld(entityManager.BeginExclusiveEntityTransaction(), reader);
entityManager.EndExclusiveEntityTransaction();
3 Likes

Here is my save file in YAML format if that could help anyone diagnose this.

Edit: To be clear, I’m not normally trying to serialize and deserialize the yaml file, I just serialized it as yaml once to make it readable for debugging.

5266920–527109–test-save.txt (99.3 KB)

Turns out I was trying to serialize entities that had a RenderMesh component. If you pass an empty object array into the SerializeWorld method it will send all the meshes and materials to that array. Then I realized I shouldn’t really serialize a bunch of meshes and materials so I’m having to rewrite a lot of systems and components so I can build the meshes and materials from component data so I can deserialize them later.

2 Likes