Cloud Save

Overview

Cloud Save is a service that stores arbitrary data in JSON format. With Cloud save, you can store, retrieve, update, and delete any data from your game. The game data can be stored in one of two types of records:

  • Game Records store game data such as event configurations and themes.
  • Player Records store user’s records such as saved game data.

Tutorials

Configuring Records

Create a New Record

Create a New Game Record Through the Admin Portal
  1. In the Game Management section of the Admin Portal, open the Cloud Save menu.

    cloud-save

  2. On the Cloud Save page, click the Add Record button.

    cloud-save

  3. Input the required information into the form below

    cloud-save

    • Input the Game Record Key using the appropriate format.
    • Input the JSON Configuration.
  4. When you’re done, click Add. The new record will be added to the list.

Create a New Record Using API

Create a New Game Record Using API

You can create a game record by following the steps below.

  1. Use the Save Namespace Level Record: POST /cloudsave/v1/admin/namespaces/{namespace}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the Key of the record.
  4. Fill out the Request Body with the record information.

Create a New Player Record Using API

You can create a player record by following the steps below.

  1. Use the Save User Level Record POST /cloudsave/v1/admin/namespaces/{namespace}/users/{userID}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the User ID for the player who the record is for.
  4. Input the Key of the record.
  5. Fill out the Request Body with the record information.

Update a Record

Update a Game Record Through the Admin Portal
  1. In the Admin Portal, go to the Cloud Save page and choose the record you want to update.

    cloud-save

  2. In the Record Detail window, go to the JSON Configuration section and click Edit.

    cloud-save

  3. Input the updated record information and click Save.

    cloud-save

Update a Record Using API

Update a Game Record Using API

You can update or replace a game record by following the steps below.

  1. Use the Save or Replace Game Record: PUT /cloudsave/v1/admin/namespaces/{namespace}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the Key of the record.
  4. Fill out the Request Body with the updated information.

Update a Player Record Using API

You can update or replace a player record by following the steps below.

  1. Use the Create or Append Player Record: PUT /cloudsave/v1/admin/namespaces/{namespace}/users/{userID}/records/{key} endpoint.
  2. Input the User ID of the player who owns the record.
  3. Input the Namespace field with the game namespace.
  4. Input the Key of the record.
  5. Fill out the Request Body with the updated information.

If the Key you use already exists, that record will be updated with the new information. If that key does not yet exist, a new record will be created for it.

Delete a Record

Delete a Game Record Through the Admin Portal
  1. In the Admin Portal, go to the Cloud Save page and choose the record you want to delete by clicking the Delete button in the Action column of that record.

cloud-save

  1. Confirm that you want to delete the record in the form that appears.
Delete a Record Using API

Delete a Game Record Using API

  1. Use the Purge all records under the given key: DELETE /cloudsave/v1/admin/namespaces/{namespace}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the record’s Key.

Delete a Player Record Using API

  1. Use the Purge player record based on its key: DELETE /cloudsave/v1/admin/namespaces/{namespace}/users/{userID}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the User ID of the user who owns the record.
  4. Input the record’s Key.

Retrieve a Record

Retrieve a Game Record Through the Admin Portal
  1. In the Admin Portal, go to the Cloud Save page and open the record you want to view by clicking the View button in the Action column.

    cloud-save

  2. The Record Detail page will open.

    cloud-save

Retrieve a Record Using API

Retrieve a Game Record Using API

Follow the steps below to retrieve a game record based on its key.

  1. Use the Retrieve a record value by its key GET /cloudsave/v1/admin/namespaces/{namespace}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the record’s Key.

You can also retrieve a list of all of the records in a namespace by following the steps below.

  1. Use the Retrieve list of records key by namespace: GET /cloudsave/v1/admin/namespaces/{namespace}/records endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the offset and limit if you want to paginate the results. If you want to retrieve the complete list, you can leave these fields blank.

Retrieve a Player Record Using API

You can retrieve a player record by its key by following the steps below.

  1. Use the Retrieve a record value by its key: GET /cloudsave/v1/admin/namespaces/{namespace}/users/{userID}/records/{key} endpoint.
  2. Input the Namespace field with the game namespace.
  3. Input the record’s Key.

Integrating Your Game with Cloud Save Using SDK

Integrating Your Game with Cloud Save at the User Level

To start integrating your game with Cloud Save, make sure you have configured the AccelByte SDK, then follow the steps below.

Unity

Set the Cloud Save URL in the Assets/Resources/AccelByteSDKConfig.json file.

{
......
"CloudSaveServerUrl": "https://api.demo.accelbyte.io/cloudsave",
......
}

UE4

Set the Cloud Save URL in the DefaultEngine.ini file.
...
CloudSaveServerUrl="https://api.demo.accelbyte.io/cloudsave"
...
Create a New Record

This example shows you how to store user data inside the UserXyzAbGame key using the SaveUserRecord() function.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string Key = “UserXyzAbGame”;
bool isPublic = false;
Dictionary<string, object> record = new Dictionary<string, object>
{
{"numRegion", 6 },
{"oilsReserve", 125.10 },
{"islandName", "tartar friendly land" },
{"buildings", new string[4] { "oilRefinery", "oilWell", "watchTower", "defendsTower" }},
{"resources", new Dictionary<string, int>{{"gas", 20 }, {"water", 100 }, {"gold", 10 }}}
};
Result recordResult = null;
cloudSave.SaveUserRecord(
key, // in which key the data should be stored
record, // the stored data, which is Dictionary instance
isPublic, // whether the record is public or private
result => { recordResult = result; } // callback upon successful save user record
);

UE4

FString Key = “UserXyzAbGame”;
FJsonObject record1Test;
record1Test.SetNumberField("numRegion", 6);
record1Test.SetNumberField("oilsReserve", 125.10);
record1Test.SetStringField("islandName", "tartar friendly land");
TArray<TSharedPtr<FJsonValue>> buildings{
MakeShareable(new FJsonValueString("oilRefinery")),
MakeShareable(new FJsonValueString("oilWell")),
MakeShareable(new FJsonValueString("watchTower")),
MakeShareable(new FJsonValueString("defendsTower"))
};
record1Test.SetArrayField("buildings", buildings);
TSharedPtr<FJsonObject> resources = MakeShareable(new FJsonObject);
resources->SetNumberField("gas", 20);
resources->SetNumberField("water", 100);
resources->SetNumberField("gold", 10);
record1Test.SetObjectField("resources", resources);
bool bSaveUserRecord1Success = false;
FRegistry::CloudSave.SaveUserRecord(
Key,
record1Test,
FVoidHandler::CreateLambda([&bSaveUserRecord1Success]()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Save user record1 success"));
bSaveUserRecord1Success = true;
}),
CloudSaveErrorHandler);

Note:

  • If the key already exists, the new record will be appended to the existing record.
Retrieve a User Record

User data stored in a private record can be retrieved using the GetUserRecord() function.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “UserXyzAbGame”;
Result<UserRecord> resultRecord = null;
cloudSave.GetUserRecord(
key, // which key should be fetched from Cloud Save service
result => { recordResult = result; } // callback upon successful retrieve user record
);

UE4

FAccelByteModelsUserRecord GetUserRecordResult;
FRegistry::CloudSave.GetUserRecord(
Key,
THandler<FAccelByteModelsUserRecord>::CreateLambda(
[&GetUserRecordResult]
(FAccelByteModelsUserRecord UserRecord)
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Get user record success"));
GetUserRecordResult = UserRecord;
}),
CloudSaveErrorHandler);

A public user record can be retrieved by another user. To get another user’s public records, you can use the GetPublicUserRecord() function.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “UserXyzAbGame”;
string userId = “123456789”;
Result<UserRecord> resultRecord = null;
cloudSave.GetPublicUserRecord(
key, // which key should be fetched from Cloud Save service
userId, // userId of the record owner
result => { recordResult = result; } // callback upon successful retrieve user record
);
Update a User Record

You can update data using the ReplaceUserRecord() function, even when the data does not exist. If the data does not exist, it will be created based on the data in the update. This data can be stored either publicly or privately.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “UserXyzAbGame”;
bool isPublic = false;
Dictionary<string, object> record = new Dictionary<string, object>
{
{"numRegion", 10 },
{"oilsReserve", 100 },
{"buildings", new string[2] { "oilRefinery", "oilWell"}},
{"resources", new Dictionary<string, int>{{"gas", 0 }, {"water", 0 }, {"gold", 0 }}}
};
Result recordResult = null;
cloudSave.ReplaceUserRecord(
key, // in which key the data should be stored / updated
record, // the updated data, which is Dictionary instance
isPublic, // whether the record is public or private
result => { recordResult = result; } // callback upon successful save user record
);

UE4

FJsonObject newRecord1Test;
newRecord1Test.SetNumberField("numRegion", 10);
newRecord1Test.SetNumberField("oilsReserve", 100);
newRecord1Test.SetStringField("islandName", "salad friendly land");
TArray<TSharedPtr<FJsonValue>> buildings{
MakeShareable(new FJsonValueString("gasRefinery")),
MakeShareable(new FJsonValueString("gasWell")),
MakeShareable(new FJsonValueString("waterTower")),
MakeShareable(new FJsonValueString("mainTower"))
};
newRecord1Test.SetArrayField("buildings", buildings);
TSharedPtr<FJsonObject> resources = MakeShareable(new FJsonObject);
resources->SetNumberField("gas", 50);
resources->SetNumberField("water", 70);
resources->SetNumberField("gold", 30);
newRecord1Test.SetObjectField("resources", resources);
FString Key = “UserXyzAbGame”;
FRegistry::CloudSave.ReplaceUserRecord(
Key,
newRecord1Test,
FVoidHandler::CreateLambda(
[&bReplaceUserRecordSuccess]
()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Replace user record success"));
bReplaceUserRecordSuccess = true;
}),
CloudSaveErrorHandler);
Delete a User Record

Use the DeleteUserRecord() function to delete a record.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “UserXyzAbGame”;
Result recordResult = null;
cloudSave.DeleteUserRecord(
Key, // which key should be deleted from Cloud Save service
result => { recordResult = result; } // callback upon successful deletion
);

UE4

bool bDeleteUserRecordSuccess = false;
FRegistry::CloudSave.DeleteUserRecord(
Key,
FVoidHandler::CreateLambda(
[&bDeleteUserRecordSuccess]
()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Delete user record success"));
bDeleteUserRecordSuccess = true;
}),
CloudSaveErrorHandler);

Integrating Your Game with Cloud Save at the Namespace Level

Create a New Record

To create a new record, use the SaveGameRecord() function.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string Key = “GameAbc”;
Dictionary<string, object> gameRecord = new Dictionary<string, object>
{
{"numRegion", 6 },
{"oilsReserve", 125.10 },
{"islandName", "tartar friendly land" },
{"buildings", new string[4] { "oilRefinery", "oilWell", "watchTower", "defendsTower" }},
{"resources", new Dictionary<string, int>{{"gas", 20 }, {"water", 100 }, {"gold", 10 }}}
};
Result recordResult = null;
cloudSave.SaveGameRecord(
key,
GameRecord,
result => { recordResult = result; }
);

UE4

FString Key = “GameAbc”;
FJsonObject record1Test;
record1Test.SetNumberField("numRegion", 6);
record1Test.SetNumberField("oilsReserve", 125.10);
record1Test.SetStringField("islandName", "tartar friendly land");
TArray<TSharedPtr<FJsonValue>> buildings{
MakeShareable(new FJsonValueString("oilRefinery")),
MakeShareable(new FJsonValueString("oilWell")),
MakeShareable(new FJsonValueString("watchTower")),
MakeShareable(new FJsonValueString("defendsTower"))
};
record1Test.SetArrayField("buildings", buildings);
TSharedPtr<FJsonObject> resources = MakeShareable(new FJsonObject);
resources->SetNumberField("gas", 20);
resources->SetNumberField("water", 100);
resources->SetNumberField("gold", 10);
record1Test.SetObjectField("resources", resources);
bool bSaveUserRecord1Success = false;
FRegistry::CloudSave.SaveGameRecord(
Key,
record1Test,
FVoidHandler::CreateLambda([&bSaveUserRecord1Success]()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Save game record1 success"));
bSaveUserRecord1Success = true;
}),
CloudSaveErrorHandler);

Note:

  • If the key already exists, the new record will be appended to the existing record.
Retrieve Game Data

Game data can be retrieved using the GetGameRecord() function.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “GameAbc”;
Result<GameRecord> resultRecord = null;
cloudSave.GetGameRecord(
key,
result => { resultRecord = result; }
);

UE4

FAccelByteModelsGameRecord GetGameRecordResult;
FRegistry::CloudSave.GetGameRecord(
Key,
THandler<FAccelByteModelsUserRecord>::CreateLambda(
[&GetGameRecordResult]
(FAccelByteModelsGameRecord GameRecord)
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Get game record success"));
GetGameRecordResult = GameRecord;
}),
CloudSaveErrorHandler);
Update Game Data

You can update game data using the ReplaceGameRecord() function, even when the data does not exist. If the data does not exist, it will be created based on the data in the update.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “UserXyzAbGame”;
Dictionary<string, object> record = new Dictionary<string, object>
{
{"numRegion", 10 },
{"oilsReserve", 100 },
{"buildings", new string[2] { "oilRefinery", "oilWell"}},
{"resources", new Dictionary<string, int>{{"gas", 0 }, {"water", 0 }, {"gold", 0 }}}
};
Result recordResult = null;
cloudSave.ReplaceGameRecord(
key, // in which key the data should be stored / updated
record, // the updated data, which is Dictionary instance
result => { recordResult = result; } // callback upon successful save user record
);

UE4

FJsonObject newRecord1Test;
newRecord1Test.SetNumberField("numRegion", 10);
newRecord1Test.SetNumberField("oilsReserve", 100);
newRecord1Test.SetStringField("islandName", "salad friendly land");
TArray<TSharedPtr<FJsonValue>> buildings{
MakeShareable(new FJsonValueString("gasRefinery")),
MakeShareable(new FJsonValueString("gasWell")),
MakeShareable(new FJsonValueString("waterTower")),
MakeShareable(new FJsonValueString("mainTower"))
};
newRecord1Test.SetArrayField("buildings", buildings);
TSharedPtr<FJsonObject> resources = MakeShareable(new FJsonObject);
resources->SetNumberField("gas", 50);
resources->SetNumberField("water", 70);
resources->SetNumberField("gold", 30);
newRecord1Test.SetObjectField("resources", resources);
FString Key = “GameAbc”;
FRegistry::CloudSave.ReplaceGameRecord(
Key,
newRecord1Test,
FVoidHandler::CreateLambda(
[&bReplaceGameRecordSuccess]
()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Replace game record success"));
bReplaceGameRecordSuccess = true;
}),
CloudSaveErrorHandler);
Delete Game Data

Use the DeleteGameRecord() function to delete game data.

Unity

CloudSave cloudSave = AccelBytePlugin.GetCloudSave();
string key = “GameAbc”;
Result deleteResult = null;
cloudSave.DeleteGameRecord(
key,
result => { deleteResult = result; }
);

UE4

bool bDeleteGameRecordSuccess = false;
FRegistry::CloudSave.DeleteGameRecord(
Key,
FVoidHandler::CreateLambda(
[&bDeleteGameRecordSuccess ]
()
{
UE_LOG(LogAccelByteCloudSaveTest, Log, TEXT("Delete game record success"));
bDeleteGameRecordSuccess = true;
}),
CloudSaveErrorHandler);