Skip to main content

Profile

Last updated on

Overview

AccelByte Foundations’ 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 weapon, 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"
}
}

Tutorials

Basic Profile

Create a Player Profile

Use the following function to create a player profile.

FAccelByteModelsUserProfileCreateRequest ProfileCreate;  
ProfileCreate.FirstName = "John";
ProfileCreate.LastName = "Doe";
ProfileCreate.Language = "en";
ProfileCreate.Timezone = "Etc/UTC";
ProfileCreate.DateOfBirth = "1970-01-01";
ProfileCreate.AvatarSmallUrl = "http://example.com/avatar-small.jpeg";
ProfileCreate.AvatarUrl = "http://example.com/avatar.jpeg";
ProfileCreate.AvatarLargeUrl = "http://example.com/avatar-large.jpeg";

FRegistry::UserProfile.CreateUserProfile(
ProfileCreate,
THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([&](const FAccelByteModelsUserProfileInfo& Result)
{
UE_LOG(LogTemp, Log, TEXT("Success to create profile"));
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogTemp, Log, TEXT("Failed: %d %s"), Code, *Message);
})
);

Retrieve a Player’s Profile

Use the following function to retrieve a player profile. This function will retrieve the player’s personal information, such as First Name, Last Name, Language, etc. Check the Get My Profile Info endpoint to learn more about the output options available.

FRegistry::UserProfile.GetUserProfile(  
THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([&](const FAccelByteModelsUserProfileInfo& Result)
{
UE_LOG(LogTemp, Log, TEXT("Success to get user profile"));
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogTemp, Log, TEXT("Failed: %d %s"), Code, *Message);
})
);

Retrieve a Player’s Public Profile

Use the following function to retrieve a player's public profile. A public profile is the profile that other players see when interacting in your game. This function will retrieve a player’s User ID, Namespace, Timezone, and Avatar URL.

FRegistry::UserProfile.GetPublicUserProfileInfo(  
UserId,
THandler<FAccelByteModelsPublicUserProfileInfo>::CreateLambda([&](const FAccelByteModelsPublicUserProfileInfo& Result)
{
UE_LOG(LogTemp, Log, TEXT("Success to get public user profile"));
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogTemp, Log, TEXT("Failed: %d %s"), Code, *Message);
})
);

Update a Player Profile

Use the following function to update a player profile.

FAccelByteModelsUserProfileUpdateRequest ProfileUpdate;  
ProfileUpdate.Language = "en";
ProfileUpdate.Timezone = "Etc/UTC";
ProfileUpdate.DateOfBirth = "2000-01-01";
ProfileUpdate.FirstName = "First";
ProfileUpdate.LastName = "Last";
ProfileCreate.AvatarSmallUrl = "http://example.com/avatar-small-2.jpeg";
ProfileCreate.AvatarUrl = "http://example.com/avatar-2.jpeg";
ProfileCreate.AvatarLargeUrl = "http://example.com/avatar-large-2.jpeg";

FRegistry::UserProfile.UpdateUserProfile(
ProfileUpdate,
THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([&](const FAccelByteModelsUserProfileInfo& Result)
{
UE_LOG(LogTemp, Log, TEXT("Success to update user profile"));
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogTemp, Log, TEXT("Failed: %d %s"), Code, *Message);
})
);

Custom Attributes

Create Custom Attributes

Custom attributes are parts of a UserProfile that are unique to a particular game, such as a custom weapon type. You can create custom attributes when creating a UserProfile.

FAccelByteModelsUserProfileCreateRequest ProfileCreate;  
ProfileCreate.FirstName = "first";
ProfileCreate.LastName = "last";
ProfileCreate.Language = "en";
ProfileCreate.Timezone = "Etc/UTC";
ProfileCreate.DateOfBirth = "1970-01-01";
ProfileCreate.AvatarSmallUrl = "http://example.com";
ProfileCreate.AvatarUrl = "http://example.com";
ProfileCreate.AvatarLargeUrl = "http://example.com";
ProfileCreate.CustomAttributes.Add("Five", "Lima Lima");
ProfileCreate.CustomAttributes.Add("Two", "Dua Loro");
ProfileCreate.CustomAttributes.Add("Seven", "Tujuh Pitu");
ProfileCreate.CustomAttributes.Add("One", "Satu Siji");

FRegistry::UserProfile.CreateUserProfile(
ProfileCreate,
THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([&](const FAccelByteModelsUserProfileInfo& Result)
{
UE_LOG(LogAccelByteUserTest, Log, TEXT(" Success"));
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogAccelByteUserTest, Log, TEXT(" Error: %d %s"), Code, *Message);
}));

Update Custom Attributes

Use the following function to update a specific custom attribute field.

TSharedPtr<FJsonObject> CustomAttributes = MakeShareable(new FJsonObject);  
CustomAttributes->SetNumberField("SomeInt", 100);
CustomAttributes->SetStringField("SomeString", “Hello World!);
CustomAttributes->SetNumberField("SomeFloat", 20.5);
CustomAttributes->SetNumberField("SomeBool", true);

AccelByte::FRegistry::UserProfile.UpdateCustomAttributes(
CustomAttributes,
THandler<FJsonObject>::CreateLambda([](const FJsonObject& Result)
{
/* do something when succeeded */
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
/* do something when fails */
})
);

use the following function to update multiple fields that have the desired value.

TSharedPtr<FJsonObject> NestedAttributes = MakeShareable(new FJsonObject);  
NestedAttributes->SetNumberField("SomeInt", 100);
NestedAttributes->SetStringField("SomeString", “Hello World!);
NestedAttributes->SetNumberField("SomeFloat", 20.5);
NestedAttributes->SetNumberField("SomeBool", true);

TSharedPtr<FJsonObject> CustomAttributes = MakeShareable(new FJsonObject);
CustomAttributes->SetObjectField(“Nested”, NestedAttributes);

AccelByte::FRegistry::UserProfile.UpdateCustomAttributes(
CustomAttributes,
THandler<FJsonObject>::CreateLambda([](const FJsonObject& Result)
{
/* do something when succeeded */
}),
FError::CreateLambda([](int32 ErrorCode, FString ErrorMessage)
{
/* do something when fails */
})
);

Retrieve Custom Attributes

Use the following function to retrieve player profile with its custom attributes.

FAccelByteModelsUserProfileInfo ProfileGet;  
FRegistry::UserProfile.GetUserProfile(
THandler<FAccelByteModelsUserProfileInfo>::CreateLambda([&](const FAccelByteModelsUserProfileInfo& Result)
{
UE_LOG(LogAccelByteUserTest, Log, TEXT(" Success"));
ProfileGet = Result;
}),
FErrorHandler::CreateLambda([&](int32 Code, FString Message)
{
UE_LOG(LogAccelByteUserTest, Log, TEXT(" Error: %d %s"), Code, *Message);
}));