I’m struggling to get the SerializeUtilityHybrid working the way I want.
I don’t want to worry about SharedComponentData, I’m only concerned with actual game state, but it seems like the Deserialize method requires at least some SharedComponentData or else it throws this error:
ArgumentException: We are reading a UnityEngine.Object however no ObjectTable was provided to the ManagedObjectBinaryReader.
Basically the method
Unity.Serialization.Binary.Adapters.Contravariant.IBinaryAdapter<UnityEngine.Object>.Deserialize
Forces you to have passed in at least 1 object, otherwise it will throw errors.
Here’s how I’m serializing:
using (var writer = new StreamBinaryWriter(SaveGamePath + fileName + SaveGameExtension))
{
SerializeUtilityHybrid.Serialize(World.DefaultGameObjectInjectionWorld.EntityManager, writer, out var objRefs);
}
I do nothing with obj refs, since it’s all mesh data that doesn’t need to be saved with game state.
The errors get thrown in when Deserialize gets called in my code here:
var localWorld = new World("local world");
using (var reader = new StreamBinaryReader(SaveGamePath + fileName + SaveGameExtension))
{
SerializeUtilityHybrid.Deserialize(localWorld.EntityManager, reader, null);
}
World.DefaultGameObjectInjectionWorld.EntityManager.MoveEntitiesFrom(localWorld.EntityManager);
Note that I’ve tried passing in a ReferencedUnityObjects with an empty array in addition to passing null in here.
And I guess the natural follow up to this is what is the best practice to putting back shared component data after deserialization? Am I going to just have to recreate all the deserialized entities and copy their data over? I really don’t want to have to serialize stuff like mesh data, since clients should be able to deal with that on their own.