Displaying achievements
Overview
The achievement service included with AccelByte Gaming Services (AGS) allows you to display available achievements and user achievements in various ways. Displaying achievements within the game will add more motivation and a sense of accomplishment for the player experience, as well as encouraging them to engage and keep making progress to unlock them all.
In this guide, you will learn how to display all available achievement configurations and a user’s achievements.
Goals
- Explain how to utilize AccelByte SDK to display available achievements based on the configuration that is set.
- Explain how to utilize AccelByte SDK to display user achievements.
Prerequisites
- Access to the AGS Admin Portal.
- AccelByte Unreal or Unity SDK, including the permissions:
- Client ID
- Client Secret
- Access to AccelByte Achievement API documentation.
- Access to the AccelByte Statistics API to configure the required information.
- Achievement configuration should exist in the related namespace.
Display available achievements
With AGS, you have the ability to display only a single achievement or multiple achievements at the same time, depending on your game UI.
Displaying a single achievement
To display a single achievement, you are required to know the achievementCode
. You can use that achievementCode
and this function to retrieve achievement info, such as an achievement's name, description, goalValue, and icons.
- Unreal Engine
- Unity
FString AchievementCode = FString("MyAchievementCode");
FRegistry::Achievement.GetAchievement(AchievementCode, THandler<FAccelByteModelsMultiLanguageAchievement>::CreateLambda([](const FAccelByteModelsMultiLanguageAchievement& Result)
{
// Do something if GetAchievement has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetAchievement has an error
UE_LOG(LogTemp, Log, TEXT("Error GetAchievement, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string achievementCode = "MyAchievementCode";
AccelBytePlugin.GetAchievement().GetAchievement(achievementCode, result =>
{
if (result.IsError)
{
// Do something if GetAchievement has an error
Debug.Log($"Error GetAchievement, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetAchievement has been successful
}
});
Display all available achievements
As opposed to displaying a single achievement, displaying all available achievements within the related namespace does not require you to provide any information. You can use this function to retrieve a list of all achievements in the related namespace, as well as its info, such as the achievement's name, description, goalValue, and icons.
- Unreal Engine
- Unity
FString Language = FString("en");
EAccelByteAchievementListSortBy SortBy = EAccelByteAchievementListSortBy::LISTORDER;
int32 Offset = 0;
int32 Limit = 50;
FRegistry::Achievement.QueryAchievements(Language, SortBy, THandler<FAccelByteModelsPaginatedPublicAchievement>::CreateLambda([](const FAccelByteModelsPaginatedPublicAchievement& Result)
{
// Do something if QueryAchievements has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if QueryAchievements has an error
UE_LOG(LogTemp, Log, TEXT("Error QueryAchievements, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}), Offset, Limit);
string language = "en";
AchievementSortBy sortBy = AchievementSortBy.LISTORDER;
int offset = 0;
int limit = 50;
AccelBytePlugin.GetAchievement().QueryAchievements(language, sortBy, result =>
{
if (result.IsError)
{
// Do something if QueryAchievements has an error
Debug.Log($"Error QueryAchievements, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if QueryAchievements has been successful
}
}, offset, limit);
Display user achievements
Displaying a player’s progress and unlocked achievements allows them to see and appreciate their progress and accomplishments within the game. You can use this function to query a player’s unlocked and in-progress achievements. This function is called from a specific player who is already logged in to AccelByte IAM.
- Unreal Engine
- Unity
EAccelByteAchievementListSortBy SortBy = EAccelByteAchievementListSortBy::LISTORDER;
int32 Offset = 0;
int32 Limit = 50;
FRegistry::Achievement.QueryUserAchievements(SortBy, THandler<FAccelByteModelsPaginatedUserAchievement>::CreateLambda([](const FAccelByteModelsPaginatedUserAchievement& Result)
{
// Do something if QueryUserAchievements has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if QueryUserAchievements has an error
UE_LOG(LogTemp, Log, TEXT("Error QueryUserAchievements, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}), Offset, Limit);
AchievementSortBy sortBy = AchievementSortBy.LISTORDER;
int offset = 0;
int limit = 50;
AccelBytePlugin.GetAchievement().QueryUserAchievements(sortBy, result =>
{
if (result.IsError)
{
// Do something if QueryUserAchievements has an error
Debug.Log($"Error QueryUserAchievements, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if QueryUserAchievements has been successful
}
}, offset, limit);
Further reading
Further reading
After you set up the achievement configurations, you can use it to integrate with your game. You can follow the documentation below:
Achievement service is also able to cover some other use cases other than progressive achievement. Please find the other documentation below to explore other use cases: