Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using Unity.Entities;
using Unity.Entities.Serialization;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.Profiling;
public class LoadWorldAsync : MonoBehaviour
[SerializeField] string fileName = "save.sav";
[SerializeField] GameObject sharedData = null;
private World localWorld;
private const string worldName = "local world";
private void OnEnable()
localWorld = new World(worldName);
private void OnDisable()
if (localWorld.IsCreated)
public async void Load()
var entityManager = localWorld.GetExistingManager<EntityManager>();
var num = SerializeUtilityHybrid.DeserializeSharedComponents(entityManager, sharedData, null);
var transaction = entityManager.BeginExclusiveEntityTransaction();
await Task.Run(() =>
using (var reader = new StreamBinaryReader(fileName))
SerializeUtility.DeserializeWorld(transaction, reader, num);
SerializeUtilityHybrid.ReleaseSharedComponents(transaction, num);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.