Cloud Saves

Save your players' data to the cloud!

Since Trail games are played in the browser, a player may start a game on one device, stop and continue on a different device. On top of that, the local storage for browsers is limited and the player may delete their data by mistake. These are some of the reasons why we created Cloud Saves; to allow you to save the player's data on the cloud and not have to worry about its persistence.


If you're using PlayerPrefs for your saves, you only need to use FileKit.SyncCloudStorage after PlayerPrefs.Save

Trail's Cloud Saves are file-based. You store a file in a specific path and we will upload it to our servers and synced to the rest of the user's devices.


Accessing the filesystem in the browser

One thing to note is that when running in the browser, you are unable to access the local filesystem. When you try reading or writing files, you will be in fact accessing an emulated filesystem in RAM.

Uploading files

When syncing your files using SyncCloudStorage, Trail checks all the files under the Cloud Storage Path and uploads them to our server. If a file already exists in our server, it will be overwritten, otherwise, they are saved to the path. This means you cannot delete an existing cloud saved file. However, you can always sync an empty file, which will effectively delete all the data in the file.

// Remember to initialize the SDK first.

string path = FileKit.GetCloudStoragePath();

// We'll assume you have a save system called MySaveSystem and your save file is called save.json.
MySaveSystem.WriteFiles(path +"/save.json");

// Now we call SyncCloudStorage to sync the save with the cloud

// We implement a call back to make sure the sync process worked. 
private void MyCallBack(Result result)
  if (result.IsError()) {

Downloading files

Accessing your Cloud Saves to load a game is even easier; Trail automatically downloads the latest version of the cloud saved files before booting your game so that they are available as soon as the game starts running. You just need to read them like any other file.

// Remember to intialize the SDK first. 

// This time we'll use the overloaded version of the method so we can verify the result.
Result result = FileKit.GetCloudStoragePath(out var path);

// We'll assume you have a save system called MySaveSystem and your save file is called save.json.
  if(MySaveSystem.FileExists(path + "/save.json"){
    MySaveSystem.LoadFile(path + "/save.json");