Asynchronous Saving and Loading

Save Game Pro Async API allows you to save your data in parallel and multi-threaded that don’t impact your game performance and uses other CPU cores and threads for processing.

Requirements

  • Scripting Runtime Version .NET 4.x Equivalent (it can be found at Player Settings)

Usage

Let save some simple data using Async API:

SaveGame.SaveAsync("simple.dat", "My Data").ContinueWith(task => {
   if (task.IsCanceled)
   {
      Debug.LogError("Save Task - Cancelled");
   }
   else if (task.IsFaulted)
   {
      Debug.LogError("Save Tsak - Faulted");
      Debug.LogException(task.Exception);
   }
   else
   {
      Debug.Log("Saved");
   }
});

Then load it back:

SaveGame.LoadAsync<string>("simple.dat").ContinueWith(task => {
   if (task.IsCanceled)
   {
      Debug.LogError("Save Task - Cancelled");
   }
   else if (task.IsFaulted)
   {
      Debug.LogError("Save Tsak - Faulted");
      Debug.LogException(task.Exception);
   }
   else
   {
      // The data is available at task.Result property
      Debug.Log(task.Result);
      Debug.Log("Saved");
   }
});

Note: ContinueWith is a C# Task method, not included by Save Game Pro.
For more information about Tasks and how to use them, check out the below resources: