Store in-game configurations in game records
Overview
The Cloud Save service enables you to store your game data, for your game use case, in JSON format. The game records stored are for global title uses that are accessible, and in some cases are editable, by the players. Storing, for example:
- A game seasonal UI theme configuration
- Game event/news information
- Players' collective game data (e.g. clan area/map), etc.
In this guide, you will learn how to utilize a game record to store your game data, display it within the game client, and modify it according to your game use case.
Goals
- Provide an understanding and overview of game records
- Provide an understanding on how to game data in game records
- Provide an understanding on how to display game records
- Provide an understanding on how to modify game records
- Provide an understanding on how to delete game records
- Explain how to utilize game records using the AccelByte SDK
Prerequisites
You will need access to:
- The Admin Portal
- The AccelByte Unreal or Unity SDK, including the permissions:
- Client ID
- Client Secret
- The AccelByte Cloud Save API documentation
Storing Data in a New Game Records
Storing Data in a New Game Records via the Admin Portal
Creating game records via the admin portal is suitable if you want to store data that does not need to be modified by the game client, and will only be retrieved by the game client. For example: Seasonal UI theme configuration, Event/News Information, etc.
To create a game record, follow the steps below:
In the Game Management section of the Admin Portal, go to the Cloud Save menu and select Game Records.
On the Cloud Save page, click the Create Game Record button.
The Add Record form will appear. Fill in the required fields.
- Input the Game Record Key using the appropriate format. You can use this as your record title and it can be used as an identifier to retrieve the record from the SDK later.
- You can also add extra validation to make sure that only the game server, or game client, can update the records by selecting your choice in the Write Permission section. See Write Permission for a full list of the available options.
- Input your data you want to store, in JSON format, under the JSON Configuration.
When you have finished, click the Add button, and the new record will be added to the list.
Storing Data in New Game Records with the SDK
This is suitable if you need game records that are dynamically created after some actions are triggered from the game client. As an example, storing public customizable map�s data. You store the data by creating a new game record using the following function.
Create a Game Record via a Client
- Unreal
- Unity
FString Key = FString("map-data");
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"));
FMultiRegistry::GetApiClient()->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);
}));
CloudSave cloudSave = MultiRegistry.GetApiClient().GetCloudSave();
string key = "map-data";
Dictionary<string, object> recordRequest = new Dictionary<string, object>
{
{"NPC1", "x:125,y:256,z:125"},
{"NPC2", "x:115,y:225,z:120"}
};
cloudSave.SaveGameRecord(key
, recordRequest
, result =>
{
if (result.IsError)
{
// Do something if SaveGameRecord an error
Debug.Log($"Error SaveGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SaveGameRecord been successful
}
});
Create a Game Record via a Server
- Unreal
- Unity
FString Key = FString("map-data");
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"));
FMultiRegistry::GetServerApiClient()->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);
}));
ServerCloudSave serverCloudSave = MultiRegistry.GetServerApiClient().GetCloudSave();
string key = "map-data";
Dictionary<string, object> recordRequest = new Dictionary<string, object>
{
{"NPC1", "x:125,y:256,z:125"},
{"NPC2", "x:115,y:225,z:120"}
};
RecordSetBy setBy = RecordSetBy.CLIENT;
serverCloudSave.SaveGameRecord(key
, recordRequest
, setBy
, result =>
{
if (result.IsError)
{
// Do something if SaveGameRecord an error
Debug.Log($"Error SaveGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if SaveGameRecord been successful
}
});
Displaying Game Records Data
The game records that are stored and created both from your Admin Portal, or game client, can be retrieved by all players. With that data, you can do whatever you want to support your game use cases. As examples, use the data to replace the UI for seasonal themes, display the data to show the updated news or events, etc.
You can retrieve a game record using the following function:
Retrieve a Game Record via a Client
- Unreal
- Unity
FString Key = FString("inGameNews");
FMultiRegistry::GetApiClient()->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);
}));
CloudSave cloudSave = MultiRegistry.GetApiClient().GetCloudSave();
string key = "inGameNews";
cloudSave.GetGameRecord(key
, result =>
{
if (result.IsError)
{
// Do something if GetGameRecord an error
Debug.Log($"Error GetGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetGameRecord been successful
}
});
Retrieve a Game Record via a Server
- Unreal
FString Key = FString("inGameNews");
FMultiRegistry::GetServerApiClient()->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);
}));
Modify Game Records Data
Modifying Game Records via the Admin Portal
Modifying a game record from your Admin Portal is suitable if you want to take manual action to adjust the data. As examples, fixing data, auditing, etc. To update a game record, follow the steps below:
In the Game Management section of the Admin Portal, go to the Cloud Save menu and select Game Records.
On the Cloud Save page, choose the record you want to update, and select View in the Action menu.
In the Record Detail, go to the JSON Configuration section and click Edit.
Input the updated information, and click Save to complete.
Modifying New Game Records with the SDK
This is suitable if your game requires updating the game records data from the game client. The data you store will be replaced with new data, by using the following function:
Modify a Game Record via a Client
- Unreal
- Unity
FString Key = "map-data";
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=100;Y=256;Z=125"));
RecordRequest->SetStringField(FString("npc2"), FString("X=100,Y=225,Z=120"));
FMultiRegistry::GetApiClient()->CloudSave.ReplaceGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecord been successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if ReplaceGameRecord has an error
}));
CloudSave cloudSave = MultiRegistry.GetApiClient().GetCloudSave();
string key = "map-data";
Dictionary<string, object> recordRequest = new Dictionary<string, object>
{
{"NPC1", "x:100,y:256,z:125"},
{"NPC2", "x:100,y:225,z:120"}
};
cloudSave.ReplaceGameRecord(key
, recordRequest
, result =>
{
if (result.IsError)
{
// Do something if ReplaceGameRecord an error
Debug.Log($"Error ReplaceGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ReplaceGameRecord been successful
}
});
Modify a Game Record via a Server
- Unreal
- Unity
FString Key = "map-data";
TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField(FString("npc1"), FString("X=100;Y=256;Z=125"));
RecordRequest->SetStringField(FString("npc2"), FString("X=100,Y=225,Z=120"));
FMultiRegistry::GetServerApiClient()->ServerCloudSave.ReplaceGameRecord(Key, *RecordRequest, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceGameRecord been successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if ReplaceGameRecord has an error
}));
ServerCloudSave serverCloudSave = MultiRegistry.GetServerApiClient().GetCloudSave();
string key = "map-data";
Dictionary<string, object> recordRequest = new Dictionary<string, object>
{
{"NPC1", "x:100,y:256,z:125"},
{"NPC2", "x:100,y:225,z:120"}
};
RecordSetBy setBy = RecordSetBy.CLIENT;
serverCloudSave.ReplaceGameRecord(key
, recordRequest
, setBy
, result =>
{
if (result.IsError)
{
// Do something if ReplaceGameRecord an error
Debug.Log($"Error ReplaceGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if ReplaceGameRecord been successful
}
});
Delete Game Record Data
Deleting New Game Records via the Admin Portal
To delete a game record, follow the steps below:
In the Game Management section of the Admin Portal, go to the Cloud Save menu and select Game Records.
On the Cloud Save page, select the record you want to delete from the list and click the Delete button under the Action menu.
The Delete Game Record confirmation modal will appear. Click Delete to continue.
Deleting New Game Records via the SDK
If your game requires you to delete game records from the SDK side, you can delete it using the following function.
Delete a Game Record via a Client
- Unreal
- Unity
FString Key = FString("map-data");
FMultiRegistry::GetApiClient()->CloudSave.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);
}));
CloudSave cloudSave = MultiRegistry.GetApiClient().GetCloudSave();
string key = "map-data";
cloudSave.DeleteGameRecord(key
, result =>
{
if (result.IsError)
{
// Do something if DeleteGameRecord an error
Debug.Log($"Error DeleteGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if DeleteGameRecord been successful
}
});
Delete a Game Record via a Server
- Unreal
- Unity
FString Key = FString("map-data");
FMultiRegistry::GetServerApiClient()->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);
}));
ServerCloudSave serverCloudSave = MultiRegistry.GetServerApiClient().GetCloudSave();
string key = "map-data";
serverCloudSave.DeleteGameRecord(key
, result =>
{
if (result.IsError)
{
// Do something if DeleteGameRecord an error
Debug.Log($"Error DeleteGameRecord, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if DeleteGameRecord been successful
}
});