Skip to main content

Display player achievements using AGS SDK

Last updated on October 24, 2024

Overview

The AccelByte Gaming Services (AGS) Achievements service 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.

This article walks you through how to display all available achievement configurations and a specific player'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, Unity, or Extend 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.

FString AchievementCode = FString("MyAchievementCode");

FRegistry::Achievement.GetAchievement(AchievementCode, THandler<FAccelByteModelsMultiLanguageAchievement>::CreateLambda([](const FAccelByteModelsMultiLanguageAchievement& Result)
{
// Do something if GetAchievement is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetAchievement has an error
}));

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.

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 is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if QueryAchievements has an error
}), 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.

EAccelByteAchievementListSortBy SortBy = EAccelByteAchievementListSortBy::LISTORDER;
int32 Offset = 0;
int32 Limit = 50;

FRegistry::Achievement.QueryUserAchievements(SortBy, THandler<FAccelByteModelsPaginatedUserAchievement>::CreateLambda([](const FAccelByteModelsPaginatedUserAchievement& Result)
{
// Do something if QueryUserAchievements is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if QueryUserAchievements has an error
}), Offset, Limit);