Skip to main content

Cloud Save

Last updated on

Overview

AccelByte Foundations’ 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 which store game data such as event configurations and themes, and
  • Player Records which store player records such as saved game data.

Metadata

Metadata allows admins and players to define the behavior of theirCloud Save records. Record metadata is defined in the request body with the field name __META. Metadata is assigned with a default value if not otherwise defined. There are several different types of metadata, including:

  • Write Permission (set_by) This metadata indicates which party modified the record and is available in the admin endpoint only. The value options are:

    • Server: the record can only be modified by the server.

    • Client: the record can be modified by both clients and the server. This is the default value.

      Write permission behavior metrics on the Game Record:
      AdminPlayer
      ServerModify, ReadRead
      ClientModify, ReadModify, Read
      Write permission behavior metrics on the Player Record:
      AdminPlayer
      Record OwnerOther Players
      ServerModify--
      ClientModifyModify-
  • Is Public Record (is_public) This metadata indicates whether the record is public or not and is available in both admin and public endpoints. The value options are:

    • True: meaning that the record is a public record.

    • False: meaning that the record is a private record. This is the default value.

      Is Public Record behavior metrics on the Player Record:
      AdminPlayer
      Record OwnerOther Players
      FalseReadRead-
      TrueReadReadRead

Managing Your Game with Cloud Save in the Admin Portal

AccelByte Foundations’ Admin Portal gives community managers and game admins an easy way to manage and integrate Cloud Save.

Create a New Game Record

  1. Open your desired game title in the Admin Portal, expand the Game Management section, click the Cloud Save menu, and select Game Records.

  2. On the Cloud Save page, select the Create Game Record button.

    cloud-save

  3. The Add Record form will appear. Fill in the required fields.

    cloud-save

    • Input the game record Key using the appropriate format as explained below.

      • Use only lowercase letters and numbers
      • Only the hyphen (-) is allowed as a separator. It cannot appear twice in a row and cannot be used to start or end the key name
    • Input the JSON Configuration.

  4. Once completed, click the Add and the new record will be added to the list.

Update a Record

Game Record

  1. To update a Game Record, go to the Game Records page, choose the record you want to update, and select View.

cloud-save

  1. In the Record Detail window, go to the JSON Configuration section and click Edit. Input the updated record information and click Save.

    cloud-save

Player Records

  1. To update a Player Record, go to the Player Records page, choose the record you want to update by inputting the correct User ID, and select View.

  2. In the Record Detail window, go to the JSON Configuration section and click Edit. Input the updated record information and click Save.

    cloud-save

    A confirmation box will appear. Click Save to complete your update.

    cloud-save

Integrating Your Game with Cloud Save at the User Level

Create a New Record

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

NOTE

If the key already exists, the new record will be appended to the existing record.

FString Key = FString("graphicQuality");

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
// 0 Low Quality, 1 Medium Quality, 2 High Quality
RecordRequest->SetNumberField(FString("textures"), 2);
RecordRequest->SetNumberField(FString("shadow"), 1);
RecordRequest->SetNumberField(FString("lighting"), 0);
RecordRequest->SetNumberField(FString("post-processing"), 2);

FRegistry::CloudSave.SaveUserRecord(Key, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString ErrorMessage)
{
// Do something if SaveUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a User Record

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

FString Key = FString("graphicQuality");

FRegistry::CloudSave.GetUserRecord(Key, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserRecord, Error Code: %d Error Message %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a Public User Record

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

FString Key = FString("playerStatus");
FString UserId = FString("SomeUserId");

FRegistry::CloudSave.GetPublicUserRecord(Key, UserId, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetPublicUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPublicUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPublicUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace 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 then be stored either publicly or privately.

FString Key = FString("graphicQuality");

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("textures"), 2);
RecordRequest->SetNumberField(FString("shadow"), 1);
RecordRequest->SetNumberField(FString("lighting"), 0);
RecordRequest->SetNumberField(FString("post-processing"), 1);

FRegistry::CloudSave.ReplaceUserRecord(Key, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace User Records Concurrently

To ensure that concurrent edits to user records aren’t overwritten, this feature gives the user an error if another client tries to submit changes to that same user record at the same time. There are two possible implementations of this feature: manual and automatic.

Manual

The manual implementation will return the error ErrorCodes::PlayerRecordPreconditionFailedException in Unreal Engine or ErrorCode.PlayerRecordPreconditionFailed in Unity if the record has been changed since it was retrieved by the client. You’ll need to input the last updated time of the record, which can be found using the GetUserRecord function.

FString Key = FString("playerEquipments");

FRegistry::CloudSave.GetUserRecord(Key, THandler<FAccelByteModelsUserRecord>::CreateLambda([&](const FAccelByteModelsUserRecord& Result)
{
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 3);
RecordRequest->SetNumberField(FString("weapon"), 4);
RecordRequest->SetNumberField(FString("ring"), 2);
RecordRequest->SetNumberField(FString("wing"), 1);
RecordRequest->SetNumberField(FString("mount"), 3);

FRegistry::CloudSave.ReplaceUserRecordCheckLatest(Key, Result.UpdatedAt, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecordCheckLatest has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceUserRecordCheckLatest has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceUserRecordCheckLatest, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Automatic

Automatic implementation will retrieve the latest update for you. You can set this as your custom modifier, which compares records that are submitted at almost the same time. When a request is submitted again, the new custom modifier will decide which record will be accepted and which record will be rejected, updated, and require submitting again.

int32 TryAttempt = 7;
FString Key = FString("playerEquipments");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 4);
RecordRequest->SetNumberField(FString("weapon"), 2);
RecordRequest->SetNumberField(FString("ring"), 1);
RecordRequest->SetNumberField(FString("wing"), 3);
RecordRequest->SetNumberField(FString("mount"), 2);

TBaseDelegate<FJsonObject, FJsonObject> PayloadModifier = TBaseDelegate<FJsonObject, FJsonObject>::CreateLambda([RecordRequest](FJsonObject LatestRecord)
{
for (auto Item : RecordRequest->Values)
{
FString Value;
if (Item.Value->TryGetString(Value))
{
LatestRecord.SetStringField(Item.Key, Value);
}
}
return LatestRecord;
});

FRegistry::CloudSave.ReplaceUserRecordCheckLatest(TryAttempt, Key, *RecordRequest, PayloadModifier, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecordCheckLatest has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceUserRecordCheckLatest has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceUserRecordCheckLatest, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Delete a User Record

Use the DeleteUserRecord() function to delete a record.

FString Key = FString("graphicQuality");

FRegistry::CloudSave.DeleteUserRecord(Key, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Integrating Your Game with Cloud Save at the Title Level

Create a New Game Record

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

NOTE

If the key already exists, the new record will be appended to the existing record.

FString Key = FString("gameMode");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("1v1"), 0);
RecordRequest->SetNumberField(FString("2v2"), 1);
RecordRequest->SetNumberField(FString("3v3"), 2);
RecordRequest->SetNumberField(FString("4v4"), 3);

FRegistry::CloudSave.SaveGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if SaveGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if SaveGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve Game Record

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

FString Key = FString("gameMode");

FRegistry::CloudSave.GetGameRecord(Key, THandler<FAccelByteModelsGameRecord>::CreateLambda([](const FAccelByteModelsGameRecord& Result)
{
// Do something if GetGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace Game Record

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.

FString Key = FString("gameMode");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("1v1"), 0);
RecordRequest->SetNumberField(FString("2v2"), 1);
RecordRequest->SetNumberField(FString("3v3"), 2);
RecordRequest->SetNumberField(FString("4v4"), 3);

FRegistry::CloudSave.ReplaceGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceGameRecord, Error Code: %d, Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace Game Record Concurrently

Just like user records, you can use this function to avoid overwriting the changes made by other users in the middle of your changes. There are both manual and automatic methods to replace game records concurrently.

Manual

The manual method will be successful only if there are no other updates on record, but will return an ErrorCodes::PlayerRecordPreconditionFailedException error for Unreal Engine or ErrorCode.GameRecordPreconditionFailed in Unity when the record has been changed since you retrieved it. You’ll need to input the timestamp of the record’s last update, which you can get from GetGameRecord.

FString Key = FString("gameMode");

FRegistry::CloudSave.GetGameRecord(Key, THandler<FAccelByteModelsGameRecord>::CreateLambda([&](const FAccelByteModelsGameRecord& Result)
{
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("1v1"), 4);
RecordRequest->SetNumberField(FString("2v2"), 3);
RecordRequest->SetNumberField(FString("3v3"), 2);
RecordRequest->SetNumberField(FString("4v4"), 1);
RecordRequest->SetNumberField(FString("5v5"), 0);

FRegistry::CloudSave.ReplaceGameRecordCheckLatest(Key, Result.UpdatedAt, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecordCheckLatest has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceGameRecordCheckLatest has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceGameRecordCheckLatest, Error Code: %d, Error Message: %s"), ErrorCode, *ErrorMessage);
}));
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Automatic

The automatic method will get the latest update for you, put it on your custom modifier, and then make the request again. In the custom modifier, you can compare the latest record with your local record to see what changes have been made.

int32 TryAttempt = 7;
FString Key = FString("gameMode");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("1v1"), 0);
RecordRequest->SetNumberField(FString("2v2"), 1);
RecordRequest->SetNumberField(FString("3v3"), 2);
RecordRequest->SetNumberField(FString("4v4"), 3);
RecordRequest->SetNumberField(FString("5v5"), 4);

TBaseDelegate<FJsonObject, FJsonObject> PayloadModifier = TBaseDelegate<FJsonObject, FJsonObject>::CreateLambda([RecordRequest](FJsonObject LatestRecord)
{
for (auto Item : RecordRequest->Values)
{
FString Value;
if (Item.Value->TryGetString(Value))
{
LatestRecord.SetStringField(Item.Key, Value);
}
}
return LatestRecord;
});

FRegistry::CloudSave.ReplaceGameRecordCheckLatest(TryAttempt, Key, *RecordRequest, PayloadModifier, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecordCheckLatest has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceGameRecordCheckLatest has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceGameRecordCheckLatest, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
;

Delete Game Record

Use the DeleteGameRecord() function to delete game data.

FString Key = FString("gameMode");

FRegistry::CloudSave.DeleteGameRecord(Key, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteGameRecord has been successuful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Integrating Your Game Server with Cloud Save

Create a New Record

Create a new record for the targeted user or game. If the record already exists, this action will merge the records with the following conditions:

  • If the field name already exists, the value will be replaced.
  • If the field name does not exist, it will append the field and its value.

User Record

You can create a user record using the following function.

FString Key = FString("playerEquipments");
FString UserId = FString("SomeUserId");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 1);
RecordRequest->SetNumberField(FString("weapon"), 2);
RecordRequest->SetNumberField(FString("ring"), 3);
RecordRequest->SetNumberField(FString("wing"), 1);
RecordRequest->SetNumberField(FString("mount"), 2);

FRegistry::ServerCloudSave.SaveUserRecord(Key, UserId, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if SaveUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can create a game record using the following function.

FString Key = FString("npcLocation");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=125;Y=256;Z=125"));
RecordRequest->SetStringField(FString("npc2"), FString("X=115,Y=225,Z=120"));

FRegistry::ServerCloudSave.SaveGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if SaveGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if SaveGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a Record

Retrieve the specified game or user’s record.

User Record

You can retrieve a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString("playerEquipments");

FRegistry::ServerCloudSave.GetUserRecord(UserId, Key, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can retrieve a game record using the following function.

FString Key = FString("npcLocation");

FRegistry::ServerCloudSave.GetGameRecord(Key, THandler<FAccelByteModelsGameRecord>::CreateLambda([](const FAccelByteModelsGameRecord& Result)
{
// Do something if GetGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a Public User Record

Retrieve the specified public user’s record. You need to input a User ID to get the specific public user record.

FString Key = FString("playerEquipments");
FString UserId = FString("SomeUserId");

FRegistry::ServerCloudSave.GetPublicUserRecord(Key, UserId, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetPublicUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPublicUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPublicUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve All Game Records

You can retrieve all the list of game records using the following function.

FRegistry::ServerCloudSave.RetrieveGameRecordsKey(THandler<FAccelByteModelsPaginatedRecordsKey>::CreateLambda([](const FAccelByteModelsPaginatedRecordsKey& Result)
{
// Do something if RetrieveGameRecordsKey has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if RetrieveGameRecordsKey has an error
UE_LOG(LogTemp, Log, TEXT("Error RetrieveGameRecordsKey, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace a Record

This function can overwrite an existing user’s or game record if it exists. If the record does not exist, it will create a new record.

User Record

You can replace a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString ("playerEquipments");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 5);
RecordRequest->SetNumberField(FString("weapon"), 2);
RecordRequest->SetNumberField(FString("ring"), 1);
RecordRequest->SetNumberField(FString("wing"), 3);
RecordRequest->SetNumberField(FString("mount"), 2);

FRegistry::ServerCloudSave.ReplaceUserRecord(UserId, Key, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can replace a game record using the following function.

FString Key = FString("npcLocation");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=125;Y=120;Z=100"));
RecordRequest->SetStringField(FString("npc2"), FString("X=75;Y=175;Z=225"));

FRegistry::ServerCloudSave.ReplaceGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Delete a Record

This function can erase the specified record.

User Record

You can delete a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString("playerEquipments");

FRegistry::ServerCloudSave.DeleteUserRecord(Key, UserId, false, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can delete a game record using the following function.

FString Key = FString("npcLocation");

FRegistry::ServerCloudSave.DeleteGameRecord(Key, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteGameRecord, Error Code: %d Error Message: %s"), ErrorMessage, *ErrorMessage);
}));

Integrating Your Game Server with Cloud Save

In this section, you will learn how to modify games and user records in the Game Server.

NOTE

You need to use a client token to call a Game Server.

Create a New Record

Create a new record for the targeted user or game. If the record already exists, this action will merge the records with the following conditions:

  • If the field name already exists, the value will be replaced.
  • If the field name does not exist, it will append the field and its value.

User Record

You can create a user record using the following function.

FString Key = FString("playerEquipments");
FString UserId = FString("SomeUserId");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 1);
RecordRequest->SetNumberField(FString("weapon"), 2);
RecordRequest->SetNumberField(FString("ring"), 3);
RecordRequest->SetNumberField(FString("wing"), 1);
RecordRequest->SetNumberField(FString("mount"), 2);

FRegistry::ServerCloudSave.SaveUserRecord(Key, UserId, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if SaveUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can create a game record using the following function.

FString Key = FString("npcLocation");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=125;Y=256;Z=125"));
RecordRequest->SetStringField(FString("npc2"), FString("X=115,Y=225,Z=120"));

FRegistry::ServerCloudSave.SaveGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if SaveGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if SaveGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error SaveGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a Record

Retrieve the specified game or user’s record.

User Record

You can retrieve a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString("playerEquipments");

FRegistry::ServerCloudSave.GetUserRecord(UserId, Key, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can retrieve a game record using the following function.

FString Key = FString("npcLocation");

FRegistry::ServerCloudSave.GetGameRecord(Key, THandler<FAccelByteModelsGameRecord>::CreateLambda([](const FAccelByteModelsGameRecord& Result)
{
// Do something if GetGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve a Public User Record

Retrieve the specified public user’s record. You need to input a User ID to get the specific public user record.

FString Key = FString("playerEquipments");
FString UserId = FString("SomeUserId");

FRegistry::ServerCloudSave.GetPublicUserRecord(Key, UserId, THandler<FAccelByteModelsUserRecord>::CreateLambda([](const FAccelByteModelsUserRecord& Result)
{
// Do something if GetPublicUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetPublicUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error GetPublicUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Retrieve All Game Records

You can retrieve all the list of game records using the following function.

FRegistry::ServerCloudSave.RetrieveGameRecordsKey(THandler<FAccelByteModelsPaginatedRecordsKey>::CreateLambda([](const FAccelByteModelsPaginatedRecordsKey& Result)
{
// Do something if RetrieveGameRecordsKey has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if RetrieveGameRecordsKey has an error
UE_LOG(LogTemp, Log, TEXT("Error RetrieveGameRecordsKey, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Replace a Record

This function can overwrite an existing user’s or game record if it exists. If the record does not exist, it will create a new record.

User Record

You can replace a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString ("playerEquipments");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetNumberField(FString("armor"), 5);
RecordRequest->SetNumberField(FString("weapon"), 2);
RecordRequest->SetNumberField(FString("ring"), 1);
RecordRequest->SetNumberField(FString("wing"), 3);
RecordRequest->SetNumberField(FString("mount"), 2);

FRegistry::ServerCloudSave.ReplaceUserRecord(UserId, Key, *RecordRequest, false, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can replace a game record using the following function.

FString Key = FString("npcLocation");
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=125;Y=120;Z=100"));
RecordRequest->SetStringField(FString("npc2"), FString("X=75;Y=175;Z=225"));

FRegistry::ServerCloudSave.ReplaceGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ReplaceGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error ReplaceGameRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Delete a Record

This function will delete the specified user record.

User Record

You can delete a user record using the following function.

FString UserId = FString("SomeUserId");
FString Key = FString("playerEquipments");

FRegistry::ServerCloudSave.DeleteUserRecord(Key, UserId, false, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteUserRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteUserRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteUserRecord, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));

Game Record

You can delete a game record using the following function.

FString Key = FString("npcLocation");

FRegistry::ServerCloudSave.DeleteGameRecord(Key, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteGameRecord has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if DeleteGameRecord has an error
UE_LOG(LogTemp, Log, TEXT("Error DeleteGameRecord, Error Code: %d Error Message: %s"), ErrorMessage, *ErrorMessage);
}));