The BlobAssetReference is not valid (Serializing/Deserializing World in ECS)
I'm trying to save a snapshot of the world's physics so I can revert back to it at a later time deterministically with the entity component system. I have it working where I can save and load one time, but on after the second save when I try to load/deserialize again I get errors saying "The BlobAssetReference is not valid. Likely it has already been unloaded or released.", and "IndexOutOfRangeException: Index 1065297994 is out of range of '2' Length." Does this mean I am disposing of something too early?
Any help would be greatly appreciated.
public void SerializeWorld()
{
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
using (var writer = new StreamBinaryWriter(_savedWorldFilename))
{
SerializeUtility.SerializeWorld(entityManager, writer, out unityMappingTable);
}
}
public void DeserializeWorld()
{
World.DefaultGameObjectInjectionWorld.EntityManager.DestroyEntity(World.DefaultGameObjectInjectionWorld.EntityManager.UniversalQuery);
if (unityMappingTable != null)
{
World localWorld = new World("local world");
var transaction = localWorld.EntityManager.BeginExclusiveEntityTransaction();
using (var reader = new StreamBinaryReader(_savedWorldFilename))
{
SerializeUtility.DeserializeWorld(transaction, reader, unityMappingTable);
}
localWorld.EntityManager.EndExclusiveEntityTransaction();
World.DefaultGameObjectInjectionWorld.EntityManager.MoveEntitiesFrom(localWorld.EntityManager);
}
}
InvalidOperationException: The BlobAssetReference is not valid. Likely it has already been unloaded or released. Unity.Entities.BlobAssetReferenceData.ValidateNonBurst () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/Blobs.cs:212) Unity.Entities.BlobAssetReferenceData.ValidateNotNull () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/Blobs.cs:228) Unity.Entities.BlobAssetReference`1[T].get_Value () (at Library/PackageCache/com.unity.entities@0.11.1-preview.4/Unity.Entities/Blobs.cs:312) Unity.Physics.Broadphase+PrepareStaticBodyDataJob.ExecuteImpl (System.Int32 index, System.Single aabbMargin, Unity.Collections.NativeArray`1[T] rigidBodies, Unity.Collections.NativeArray`1[T] aabbs, Unity.Collections.NativeArray`1[T] points, Unity.Collections.NativeArray`1[T] filtersOut) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Collision/World/Broadphase.cs:816) Unity.Physics.Broadphase+PrepareStaticBodyDataJob.Execute (System.Int32 index) (at Library/PackageCache/com.unity.physics@0.4.0-preview.5/Unity.Physics/Collision/World/Broadphase.cs:805) Unity.Jobs.IJobParallelForDeferExtensions+JobParallelForDeferProducer`1[T].Execute (T& jobData, System.IntPtr additionalPtr, System.IntPtr bufferRangePatchData, Unity.Jobs.LowLevel.Unsafe.JobRanges& ranges, System.Int32 jobIndex) (at Library/PackageCache/com.unity.jobs@0.2.10-preview.12/Unity.Jobs/IJobParallelForDefer.cs:58)