メインコンテンツまでスキップ

クラウドセーブに SDK を使用する - クラウドセーブ - (Unity モジュール)

Last updated on June 23, 2025

Unwrap the Wrapper

In this tutorial, you will learn how to implement AccelByte Gaming Services (AGS) Cloud Save using the AGS Software Development Kit (SDK) to save and fetch game options for music and sound effects (SFX) volumes.

AGS Cloud Save supports the following record types:

  • Player Record: A record type used to save player data, such as game options and preferences.
  • Game Record: A record type used to save game data, such as game announcements, event configurations, and more.

In Byte Wars, there is a game instance wrapper defined in the CloudSaveEssentialsWrapper class. This wrapper is used to manipulate the AGS Cloud Save Player Record values to save the game options.

In this tutorial, you will use the CloudSaveEssentialsWrapper_Starter wrapper, which is a starter version of the CloudSaveEssentialsWrapper class, to begin implementing the feature from scratch.

What's in the Starter Pack

To follow this tutorial, you will use the starter wrapper class called CloudSaveEssentialsWrapper_Starter. This wrapper is defined in the following file:

  • C# file: Assets/Resources/Modules/CloudSaveEssentials/Scripts/CloudSaveEssentialsWrapper_Starter.cs

There is also a model class containing helper functions and variables, defined in the following file:

  • C# file: Assets/Resources/Modules/CloudSaveEssentials/Scripts/CloudSaveEssentialsModels.cs

The CloudSaveEssentialsWrapper_Starter class includes several pre-defined components:

  • Helper variables to reference the AGS Game SDK interfaces. These variables are assigned when the wrapper is initialized:

    private CloudSave cloudSave;
    private Lobby lobby;

    private void Start()
    {
    cloudSave = AccelByteSDK.GetClientRegistry().GetApi().GetCloudSave();
    lobby = AccelByteSDK.GetClientRegistry().GetApi().GetLobby();
    }

The CloudSaveEssentialsModels class includes the following helpers:

  • Constants for record keys and item names used to save data in AGS Cloud Save:

    public class CloudSaveEssentialsModels
    {
    public const string GameOptionsRecordKey = "GameOptions-Sound";
    public const string MusicVolumeItemName = "musicvolume";
    public const string SfxVolumeItemName = "sfxvolume";
    }

Implement Cloud Save with AGS Game SDK

In this section, you will implement Cloud Save using the AGS Game SDK to save, retrieve, and delete a Player Record.

  1. Open the CloudSaveEssentialsWrapper_Starter class. Begin by creating a function to save a record. Add the following function to the class. This function sends a request to save a record by providing the record key and values. When the request is completed, it calls the callback function.

    public void SaveUserRecord(string recordKey, Dictionary<string, object> recordRequest, ResultCallback resultCallback)
    {
    cloudSave.SaveUserRecord(
    recordKey,
    recordRequest,
    result => OnSaveUserRecordCompleted(result, resultCallback),
    true
    );
    }
  2. Next, create the callback function to handle the result of the save operation. This function simply logs whether the request succeeded or failed.

    private void OnSaveUserRecordCompleted(Result result, ResultCallback customCallback = null)
    {
    if (!result.IsError)
    {
    BytewarsLogger.Log("Save Player Record from Client successful.");
    }
    else
    {
    BytewarsLogger.LogWarning($"Save Player Record from Client failed. Message: {result.Error.Message}");
    }

    customCallback?.Invoke(result);
    }
  3. Now, create a new function to retrieve the record values. This function sends a request to retrieve a record by providing the record key. When the request is completed, it calls the callback function.

    public void GetUserRecord(string recordKey, ResultCallback<UserRecord> resultCallback)
    {
    cloudSave.GetUserRecord(
    recordKey,
    result => OnGetUserRecordCompleted(result, resultCallback)
    );
    }
  4. Then, create the callback function to handle the result of the get operation. This function logs whether the request succeeded or failed.

    private void OnGetUserRecordCompleted(Result<UserRecord> result, ResultCallback<UserRecord> customCallback = null)
    {
    if (!result.IsError)
    {
    BytewarsLogger.Log("Get Player Record from Client successful.");
    }
    else
    {
    BytewarsLogger.LogWarning($"Get Player Record from Client failed. Message: {result.Error.Message}");
    }

    customCallback?.Invoke(result);
    }
  5. Create a new function to delete the record. This function sends a request to delete a record by providing the record key. When the request is completed, it calls the callback function.

    public void DeleteUserRecord(string recordKey, ResultCallback resultCallback)
    {
    cloudSave.DeleteUserRecord(
    recordKey,
    result => OnDeleteUserRecordCompleted(result, resultCallback)
    );
    }
  6. Finally, create the callback function to handle the result of the delete operation. This function logs whether the request succeeded or failed.

    private void OnDeleteUserRecordCompleted(Result result, ResultCallback customCallback = null)
    {
    if (!result.IsError)
    {
    BytewarsLogger.Log("Delete Player Record from Client successful.");
    }
    else
    {
    BytewarsLogger.LogWarning($"Delete Player Record from Client failed. Message: {result.Error.Message}");
    }

    customCallback?.Invoke(result);
    }

Resources