Skip to main content

Unlock player achievements using AGS SDK

Last updated on July 16, 2024

Overview

The AccelByte Gaming Services (AGS) Achievements service allows you to choose various ways to unlock user achievements depending on your game needs. Unlocking user achievements is dependent on the achievement configuration you have set up. You can only manually unlock a non-incremental achievement. For the an incremental achievement, it will be automatically unlocked once the player has already achieved the achievement goal value.

In this guide, you will learn how the Achievements service unlock process works.

Goals

  • Explain how to utilize AccelByte SDK to unlock an achievement.

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.

Unlock an achievement

There are two ways to unlock a player's achievement: either from the game client or from the game dedicated server.

Unlock an achievement from the game client

This unlocking process is suitable for unlocking achievements that do not affect the gameplay, such as the player's first time logging in, the player's first time inviting a friend, etc.

info

This unlocking process can only be used for non-incremental achievement configuration.

To unlock the achievement, you are required to know the achievementCode. You can use that achievement code and the following function to unlock the achievement:

FString AchievementCode = FString("MyAchievementCode");

FRegistry::Achievement.UnlockAchievement(AchievementCode, FVoidHandler::CreateLambda([]()
{
// Do something if UnlocKAchievement is successful
}), FErrorHandler:: CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UnlockAchievement has an error
}));

Unlock an achievement from the dedicated server

Unlocking an achievement from the server is usually done after a match is completed. To unlock an achievement from the dedicated server, you are required to have the userID of the user you want to grant the achievement and the achievementCode. You can use that information and the following function to unlock the achievement:

FString AchievementCode = FString("MyAchievementCode");
FString UserId = FString("UserId");

FRegistry::ServerAchievement.UnlockAchievement(UserId, AchievementCode, FVoidHandler::CreateLambda([]()
{
// Do something if UnlockAchievement is successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if UnlockAchievement has an error
}));