Profile
Overview
AccelByte Gaming Services (AGS) Starter 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.
- Unreal Engine
- Unity
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);
})
);
Result<UserProfile> createProfileResult = null;
AccelBytePlugin.GetUserProfiles().CreateUserProfile(
new CreateUserProfileRequest
{
language = "en",
timeZone = "Asia/Jakarta",
firstName = "John",
lastName = "Doe",
dateOfBirth = "1990-01-01"
},
result => createProfileResult = result);
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.
- Unreal Engine
- Unity
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);
})
);
Result<UserProfile> getProfileResult = null;
AccelBytePlugin.GetUserProfiles().GetUserProfile(result => { getProfileResult = result; });
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.
- Unreal Engine
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.
- Unreal Engine
- Unity
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);
})
);
Result<UserProfile> updateResult = null;
var profileUpdate = new UpdateUserProfileRequest
{
firstName = "John",
lastName = "Doe",
language = "en"
};
AccelBytePlugin.GetUserProfiles().UpdateUserProfile(profileUpdate, result => { updateResult = result; });
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.
- Unreal Engine
- Unity
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);
}));
userProfiles.CreateUserProfile(
new CreateUserProfileRequest
{
language = "en",
timeZone = "Asia/Jakarta",
firstName = "first",
lastName = "last",
dateOfBirth = "2000-01-01",
customAttributes = new Dictionary<string, object>
},
result => createProfileResult = result);
Update Custom Attributes
Use the following function to update a specific custom attribute field.
- Unreal Engine
- Unity
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 */
})
);
var customAttributes = new Dictionary<string, object>
{
{"number_int", 123}, {"number_float", 125.125}, {"string", "jahe santan gula aren"},
};
Result<Dictionary<string, object>> updatedAttributes = null;
userProfiles.UpdateCustomAttributes(customAttributes, result => updatedAttributes = result);
use the following function to update multiple fields that have the desired value.
- Unreal Engine
- Unity
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 */
})
);
customAttributes.Clear();
customAttributes.Add(
"nested",
new AClass
{
SomeNestedClass = new NestedClass {SomeBool = true, SomeDate = DateTime.Today},
SomeInt = 7070,
SomeString = "ur nee"
});
Result<Dictionary<string, object>> updatedAttributes2 = null;
userProfiles.UpdateCustomAttributes(customAttributes, result => updatedAttributes2 = result);
Retrieve Custom Attributes
Use the following function to retrieve player profile with its custom attributes.
- Unreal Engine
- Unity
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);
}));
Result<Dictionary<string, object>> getCustomAttributesResult = null;
userProfiles.GetCustomAttributes(result => { getCustomAttributesResult = result; });