Hello community!
We’ve been having some issues with deserializing our entities. At the moment we have 2 major issues that we want some help with. 1) Losing our child component information after deserializing. 2) unclear on how to save the out object[ ] that is made when serializing.
-
The main issue here is when we load the save file the parent entities lose their Child BufferComponent. This leads to not being able to properly rotate or move our entity because its children are no longer attached. Is this just something we need to work around? We have tried to re-add the Child buffer, but we have had no luck in being able to do this.
-
When Serializing the world, it seems we need to save the out Object[ ] as well so we can Deserialize at a later time. Saving and Loading on the same play session works fine, 1 time. But trying to do so after the play session or 2 times throws errors on being unable to use that Object[ ]. How would we go about saving this and why isn’t this just done by default?
Any help on these topic would be amazing. Code is below.
private void SaveMethod()
{
using var saveWorld = new World("saveWorld", WorldFlags.Staging);
using var entityArray = saveQuery.ToEntityArray(Allocator.Temp);
var entityRemap = new NativeArray<EntityRemapUtility.EntityRemapInfo>(EntityManager.EntityCapacity, Allocator.Temp);
saveWorld.EntityManager.CopyEntitiesFrom(EntityManager, entityArray);
using var streamWriter = new StreamBinaryWriter($"{Application.dataPath}/saveData");
SerializeUtility.SerializeWorld(saveWorld.EntityManager, streamWriter, out objectOuputArr, entityRemap);
PlayerPrefs.SetString("objArray", objectOuputArr.ToString());
PlayerPrefs.Save();
}
private void LoadMethod()
{
var objArray = PlayerPrefs.GetString("objArray", objectOuputArr.ToString());
using var loadWorld = new World("loadWorld", WorldFlags.Staging);
var loadEntityManager = loadWorld.EntityManager;
var eeTrans = loadEntityManager.BeginExclusiveEntityTransaction();
using var streamReader = new StreamBinaryReader($"{Application.dataPath}/saveData");
SerializeUtility.DeserializeWorld(eeTrans, streamReader, objectOuputArr);
loadEntityManager.EndExclusiveEntityTransaction();
EntityManager.CopyAndReplaceEntitiesFrom(loadEntityManager);
}