Skip to main content

Profile

Last updated on

Overview

AccelByte Cloud's Profile services allow players to display information about themselves such as their Name, Location, Date of Birth, and Photos. Beyond these basic attributes, you can also create your own attributes to customize the player profiles for your game. For example, you can add attributes that include a player's level or rank. When you add these attributes to the Profile service, that information will be displayed on each player's profile.

Custom Attributes

Custom Attributes can be implemented using the SDK. In the sample code below four custom attributes have been added: level, rank, equipped sword, and equipped shield. When this code is implemented, these attributes will appear in each player's profile.

{
"userId": "string",
"namespace": "string",
"firstName": "string",
"lastName": "string",
"avatarSmallUrl": "string",
"avatarUrl": "string",
"avatarLargeUrl": "string",
"status": "ACTIVE",
"language": "string",
"timeZone": "string",
"dateOfBirth": "2019-12-22",
"customAttributes": {
"level": "1",
"rank": "Grand Master",
"activeWeapon": "Copper Sword",
"activeShield": "Pot Lid"
}
}

Prerequisites

Implement Profiles using the Client SDKs

Create a Player Profile

Use the following function to create a player profile.

FAccelByteModelsUserProfileCreateRequest ProfileCreateRequest;
ProfileCreateRequest.FirstName = FString("MyFirstName");
ProfileCreateRequest.LastName = FString("MyLastName");
ProfileCreateRequest.AvatarSmallUrl = FString("https://example.com/avatar-small.jpeg");
ProfileCreateRequest.AvatarLargeUrl = FString("https://example.com/avatar-large.jpeg");
ProfileCreateRequest.AvatarUrl = FString(“https://example.com/avatar.peg”);
ProfileCreateRequest.DateOfBirth = FString("1999-10-12");
ProfileCreateRequest.Language = FString("en");
ProfileCreateRequest.Timezone = FString("Etc/UTC");

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

Retrieve a Player Profile

You can retrieve a player profile using the following function. This function will retrieve the player's personal information, such as First Name, Last Name, Language, etc.

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

Retrieve a Player's Public Profile

If you need to get a player's public profile, you can use the following function. The public profile is the profile that other players see when interacting in the game. When retrieving a player's public profile, you will receive the player's User ID, Namespace, Timezone, and Avatar URL.

FString UserId = FString("SomeUserId");

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

Update a Player Profile

Use the following function to update a player profile.

FAccelByteModelsUserProfileUpdateRequest ProfileUpdateRequest;
ProfileUpdateRequest.FirstName = FString("MyNewFirstName");
ProfileUpdateRequest.LastName = FString("MyNewLastName");
ProfileUpdateRequest.AvatarSmallUrl = FString("https://example.com/avatar-small-new.jpeg");
ProfileUpdateRequest.AvatarLargeUrl = FString("https://example.com/avatar-large-new.jpeg");
ProfileUpdateRequest.AvatarUrl = FString("https://example.com/avatar-new.jpeg");
ProfileUpdateRequest.DateOfBirth = FString("2000-11-13");
ProfileUpdateRequest.Language = FString("en");
ProfileUpdateRequest.Timezone = FString("Etc/UTC");

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

Update Custom Attributes

The following function can be used to update a specific custom attribute field.

TSharedPtr<FJsonObject> CustomAttributes = MakeShareable(new FJsonObject);
CustomAttributes->SetNumberField("Level", 50);
CustomAttributes->SetNumberField("Armor", 25);
CustomAttributes->SetNumberField("Weapon", 20);

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

Retrieve Custom Attributes

You can retrieve a player profile with its custom attributes using the following function.

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

Retrieve Public Custom Attributes

You can retrieve a public player profile with custom attributes using the following function and specifying the user ID.

FString UserId = FString("SomeUserId");

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

Connect Custom Services to Profiles using the Server SDKs

SDK Initialization

Before using the Cloud Basic service (which includes the Profile service) from the SDK, you will need to initialize your server-side SDK to ensure you are authorized and able to perform create, read, update, and delete actions.

Golang SDK Initialization

Before using the Basic service from the Golang SDK, you will need to initialize the SDK by following the steps below:

userProfileService := &basic.UserProfileService{
Client: factory.NewBasicClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}

Once completed, you can use the Golang SDK to create, read, update, or delete the Basic service from your serverless app.

Python SDK Initialization

Before using the Basic service from the Python SDK, you will need to initialize the SDK by following the steps below:

Once completed, you can use the Python SDK to create, read, update, or delete the Basic service from your serverless app.

.NET (C#) SDK Initialization

Before using the Basic service, you will need to set some permissions. Use the following .NET namespaces:

using AccelByte.Sdk.Api.Basic.Model;
using AccelByte.Sdk.Api.Basic.Operation;
using AccelByte.Sdk.Api.Basic.Wrapper;

Java SDK Initialization

Before using the Basic service, you will need to set some permissions. Initialize the UserProfile wrapper from the Basic service using the following code:

UserProfile wProfile = new UserProfile(sdk);

Once completed, you can use the SDK to create, read, update, or delete player profiles.

Create a Player Profile

Use the following function to create a player profile.

userProfileService := &basic.UserProfileService{
Client: factory.NewBasicClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}

Delete a Player Profile

Use the following function to delete a player profile:

err := userProfileService.DeleteUserProfile(input)
if err != nil {
return err
}

return nil

Retrieve a Player Profile

Use the following function to retrieve a public profile:

ok, err := userProfileService.PublicGetUserProfileInfo(input)
if err != nil {
logrus.Error(err)
return err
}
return nil

Update a Player Profile

Use the following function to update a player profile:

ok, err := userProfileService.PublicUpdateUserProfile(input)
if err != nil {
logrus.Error(err)
return err
}
return nil