☁️Cloud Save
Like what you're seeing?
Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!
Introduction
Cloud save also known as Steam Remote Storage allows you to save a file and have it synced to the "cloud" e.g. Steam's servers so that the same file is available to that user on any machine they log into.
Quote from Valve's documentation
The Steam Cloud provides an easy and transparent remote file storage system for your game. Files specified in the Auto-Cloud configuration or written to disk (created, modified, deleted, etc.) using the Cloud API will automatically be replicated to the Steam servers after the game exits.
If the user changes computers, the files are automatically downloaded to the new computer before the game launches. The game can then access the files by reading them through the Cloud API or reading them directly from the disk as usual. Avoid machine-specific configurations such as video settings.
The Steam Client does the work of ensuring that the files are kept synchronized across all computers the user may be accessing.
Users can globally disable Cloud synchronization in the Steam Settings under Cloud by unchecking "Enable Steam Cloud synchronization for applications which support it."
Steam Remote Storage
The Best Way
aka the Steam Cloud API. This is the superior method in every way and when you're using Heathen's Steamworks Complete it's easier to code for than writing a text file to disk so it's also the easier method.
Steam Auto-Cloud
Not Recommended
Steam Auto-Cloud is an alternative to the Steam Cloud API that allows apps to use Steam Cloud without writing code or modifying the game in any way. It only requires that you specify the file groups which you want persisting in the Cloud. Steam will automatically sync the groups of files when the application launches and exits.
While this might appear simpler on the surface it doesn't save you any effort at all in that you must still write code to read and write your files to the user's local disk. That code is no simpler and is in most cases more complex than the code required to save directly to Steam Cloud API using Heathen's Steamworks Complete.
In addition, this gives you no control over what is saved, it will attempt to sync everything in that folder so of course you do not want to store system-specific things there as that would interfere with running the game on other systems and you do not want to store large things that shouldn't be synced there. This means you end up needing to manage multiple save locations.
For more information on Steam's Auto Cloud and its configuration read this article.
Examples
Check Cloud Is Enabled
C#
// You will need to add the following namespace
using CloudAPI = HeathenEngineering.SteamworksIntegration.API.RemoteStorage.Client;
// Then anywhere in your script you can use this to check enabled overall
// If true then it is enabled for the app and user
if(CloudAPI.IsEnabled)
{
//Yes it is
}
else
{
//No it is not
}
// If you want to check the app or user on their own
// Does the user have it turned on
if(CloudAPI.IsEnabledForAccount)
{
//The user has enabled cloud storage
}
else
{
//The user has disabled cloud storage for this app
}
// Does the developer (and Valve) have it turned on
if(CloudAPI.IsEnabledForApp)
{
//You have enabled cloud storage in the app configuration
}
else
{
//You or Valve have disabled cloud storage in the app configuration
}
Check Remaining Storage Space
Get a List of Files
C#
// You will need to add the following namespace
using CloudAPI = HeathenEngineering.SteamworksIntegration.API.RemoteStorage.Client;
// You can list all the files stored for this app
RemoteStorageFile[] files = CloudAPI.GetFiles();
// Or you can filter it by file name extension
RemoteStorageFile[] files = CloudAPI.GetFiles(".profile");
Data Model
For more information on creating a Data Model see Notes: Unity Data Model Tool
profiles.Refresh();
This will update the list of available files which we can iterate over via
foreach(var file in dataModel.availableFiles)
{
Debug.Log("Found a file named: " + file.name);
}
Read a File
C#
// You will need to add the following namespace
using CloudAPI = HeathenEngineering.SteamworksIntegration.API.RemoteStorage.Client;
The RemoteStorageFile object returned from the list operation can be used to read the data of files as a byte[], or string or to cast the data to any serializable data type.
Assuming a serializable data type MyDataType
Assuming a file RemoteStorageFile named dataFile:
//Get byte[]
byte[] data = dataFile.Data;
//Get string
string text = dataFile.ToString();
//Get an object
MyDataType obj = dataFile.ToJson<MyDataType>();
Alternatively, if you know the name of the file you can read it directly from the API
//Get byte[]
byte[] data = CouldAPI.FileRead("TheFilesName");
//Get string
string text = CloudAPI.FileReadString("TheFilesName", System.Text.Encoding.UTF8);
//Get an object
MyDataType obj = CloudAPI.FileReadJson<MyDataType>("TheFilesName", System.Text.Encoding.UTF8);
If you prefer you can read the files asynchronously
//Get byte[]
CouldAPI.FileReadAsync("TheFilesName", (data, hasError) =>
{
if(!hasError)
{
//data is your byte[]
}
});
Data Mode
For more information on creating a Data Model see Notes: Unity Data Model Tool
This example assumes "file" is a record found in dataModel.availableFiles
dataModel.LoadFileAddress(file);
Write a File
C#
// You will need to add the following namespace
using CloudAPI = HeathenEngineering.SteamworksIntegration.API.RemoteStorage.Client;
You can write a file to the remote storage system using the following methods
//Save a byte[] ... assumes data is a byte[]
CloudAPI.FileWrite("TheFileName", data);
//Save a string ... assumes data is a string
CloudAPI.FileWrite("TheFileName", data, System.Text.Encoding.UTF8);
//Save an object ... assumes data is a serializable class or struct
CloudAPI.FileWrite("TheFileName", data, System.Text.Encoding.UTF8);
The same commands can be used asynchronously
CloudAPI.FileWriteAsync("TheFileName", data, (result, hasError) =>
{
if(!hasError)
Debug.Log("File written");
});
Data Model
For more information on creating a Data Model see Notes: Unity Data Model Tool
dataModel.data.difficulty = 3;
dataModel.Save("profileSettings");
Last updated