Skip to main content

Store player attributes in public records

Last updated on April 4, 2024

Overview

The Cloud Save service enables you to store your players' data publicly. Storing publicly means you're allowing other players to read specific player's data. You can retrieve, modify, and delete any data that you store, which is in JSON format.

The data stored is usually non-sensitive data which is fine to be displayed publicly to other players, and there are no privacy rules for the data. Storing, for example:

  • Player profile data such as player status, player info, job, role, tier, level, etc.
  • Player customized weapon loadout, etc.

In this guide, you will learn how to utilize a player record to store your player data publicly, display it within the game client, and modify it according to your game use case.

Goals

The goals of this section are to:

  • Provide an understanding and overview of public player records
  • Provide an understanding on how to store player data in public player records
  • Provide an understanding on how to display public player records
  • Provide an understanding on how to modify public player records
  • Provide an understanding on how to delete public player records
  • Explain how to utilize public player records using the AccelByte SDK

Prerequisites

You will need access to:

  • The Admin Portal
  • The AccelByte Unreal or Unity SDK, including the required permission:
    • Client ID
    • Client Secret
  • The AccelByte Save API documentation

Storing User Data in a Public Player Record

Storing user data is important for a game, because this can make the game experience more enjoyable as players don't need to start over every time they play.

There are two methods to store Cloud Save public player records that you can choose, based on your game use case:

  • Store via the game client: the data stored can be modified from both game client or game server.
  • Store via the game server: the data stored via a game server can only be modified by a game server.

The only difference between the two methods above is the write permission that can be assigned for the record. For more information about record write permission, check this section.

Store user data in public player records via a game client

This is suitable for storing data such as player information, for example player weapon loadouts.

This example shows you how to store user data inside the playerInformation key, via the game client.

note

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

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInformation";

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField("FirstName", "John");

ApiClient->CloudSave.SaveUserRecord(Key
, *RecordRequest
, true
, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if SaveUserRecord has an error
}));

Store user data in public player records via a game server

This is suitable for storing data such as player rank or tier, that is updated by specific game logic, and not triggered manually by the player.

This example below shows you how to store user data inside the playerTier key, via the game server.

Unreal Engine
FServerApiClientPtr ApiServer = FMultiRegistry::GetServerApiClient();

FString Key = "playerTier";
FString UserId = "Player User Id";
ESetByMetadataRecord SetBy = ESetByMetadataRecord::SERVER;

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField("Rank", "Legend");

ApiServer->ServerCloudSave.SaveUserRecord(Key
, UserId
, SetBy
, true
, *RecordRequest
, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if SaveUserRecord has an error
}));

Display public player record data

You can retrieve and display the records you store accordingly based on your game use case. There are two general approaches to displaying player records, based on the record owner:

  • Own public player records. For example: a my player info page.
  • Other user public player records. For example: other users' player info page.

Display your own public player record

This example below shows you how to retrieve user data inside the playerInfo key.

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInfo";

ApiClient->CloudSave.GetUserRecord(Key
, THandler<FAccelByteModelsUserRecord>::CreateLambda([](FAccelByteModelsUserRecord Result)
{
// Do something if GetUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if GetUserRecord has an error
}));

Display other use public player records

A public user record can be retrieved by another user. This example below shows you how to retrieve other user player records data inside the playerInfo key.

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInfo";
FString UserId = "Player User Id";

ApiClient->CloudSave.GetPublicUserRecord(Key
, UserId
, THandler<FAccelByteModelsUserRecord>::CreateLambda([](FAccelByteModelsUserRecord Result)
{
// Do something if GetPublicUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if GetPublicUserRecord has an error
}));

Modify public player record data

Player record data can be modified based on your game use case. There are two methods to modify Cloud Save public player records that you can choose based on your use case:

  1. Modify via a game client. This is suitable if you want to allow your player to modify their player records. For example: user update player information.
  2. Modify via a game server. This is suitable if you only want the game server to be able to modify player records. For example: a game server assigns a player a new rank or tier.

Modify public player records via a game client

There are two methods that you can use to modify the public player records:

  1. Replace: is suitable if you want to replace the entire data with new content. If the record does not exist, it will be created based on the new data, and if the record already exists, it will replace all of it.
  2. Append: is suitable if you only want to add new keys and values ​​to player records. This process is lighter when compared to Replace.

Replace a user's public player record

The example below shows you how to replace user data inside the playerInfo key.

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInfo";

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField("FirstName", "Doe");

ApiClient->CloudSave.ReplaceUserRecord(Key
, true
, *RecordRequest
, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if ReplaceUserRecord has an error
}));

Append a user's public player record

This example below shows you how to append user data inside the playerInfo key.

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInfo";

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField("LastName", "Doe");

ApiClient->CloudSave.SaveUserRecord(Key
, *RecordRequest
, true
, FVoidHandler::CreateLambda([]()
{
// Do something if SaveUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if SaveUserRecord has an error
}));

Modify public player records via a game server

A Game server has the most permissions for modifying public player records data. For more information about the record write permission check this section.

The example below shows you how to modify player record data inside the playerTier key via the game server.

Unreal Engine
FServerApiClientPtr ApiServer = FMultiRegistry::GetServerApiClient();

FString Key = "playerTier";
FString UserId = "Player User Id";
ESetByMetadataRecord SetBy = ESetByMetadataRecord::SERVER;

TSharedPtr<FJsonObject> RecordRequest = MakeShareable(new FJsonObject);
RecordRequest->SetStringField("Rank", "Diamond");

ApiServer->ServerCloudSave.ReplaceUserRecord(Key
, SetBy
, true
, UserId
, *RecordRequest
, FVoidHandler::CreateLambda([]()
{
// Do something if ReplaceUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if ReplaceUserRecord has an error
}));

Delete public player records for a specific user

You can also delete public player record data. Deleting player record data can be done from a game client or game server.

Delete a user's public player record via a game client

This example below shows you how to delete user record data with the playerInfo key, via a game client.

Unreal Engine
FApiClientPtr ApiClient = FMultiRegistry::GetApiClient();

FString Key = "playerInfo";

ApiClient->CloudSave.DeleteUserRecord(Key
, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if DeleteUserRecord has an error
}));

Delete a user's public player record via a game server

This example below shows you how to delete user record data with the playerTier key, via a game server.

Unreal Engine
FServerApiClientPtr ApiServer = FMultiRegistry::GetServerApiClient();

FString Key = "playerTier";
FString UserId = "Player User Id";

ApiServer->ServerCloudSave.DeleteUserRecord(Key
, UserId
, true
, FVoidHandler::CreateLambda([]()
{
// Do something if DeleteUserRecord is successful
})
, FErrorHandler::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
// Do something if DeleteUserRecord has an error
}));