skip to Main Content

Handling Steam Achievements – Steam Integration Part 2

In this post we’re going to add Achievements to the Third Person Template project we have created in the previous post.

Setting up Achievements Name and ID

Before we type any code, we need to inform our game about each achievement (including the name and it’s ID). Remember that Steam offers the Spacewar game as a sample project in order to integrate any platform specific features to our game that hasn’t yet been Greenlit. Having said that, we’re going to use Spacewar’s achievements for our game.

To inform our game about each achievement, open up the DefaultEngine.ini located inside the Config folder and in [OnlineSubsystemSteam] category, add the following lines:

The id and name of each achievement was retrieved from the following Steamworks screenshot:

achievements_spacewar

If your game gets Greenlit, you can add your own achievements.

Progressing Achievements

In order to progress any achievement, we’re going to use the following logic:

  • We’re going to cache each achievement when the game starts (BeginPlay).
  • If the player completes an achievement, we’re going to search the cached achievements and if the achievement is valid we’re going to complete it.

Open up the header file of your Character class and add the following header file:

#include "OnlineStats.h"

Then, add the following code:

Before we implement any more logic, inside your character’s source file, add the following libraries and macros:

The reason we wrap each achievement inside a macro is because it’s less prone to errors since we can avoid typing wrong strings later in our code. Let’s implement the QueryAchievements functions and BeginPlay:

Then, let’s implement the UpdateAchievementProgress function:

The last thing we need is to implement the achievement functions. These function are going to call the UpdateAchievementProgress function with the desired Achievement they wish to complete. I’ve added the BlueprintCallable specifier in order to test them using key binds in the Blueprint graph. Here is the logic for each function:

At this point, launch your game on Standalone mode (this assumes that you have enabled the Online Subsystem Steam plugin which resides in the Online Platform category) and test your achievements!

This Post Has 5 Comments

  1. Hi orfeasel,
    I cant find those headers such as “#include “OnlineStats.h”” ,#include “OnlineAchievementsInterface.h”,etc.
    My engine version is 4.14.1,Can you help please?

  2. You don’t need it for this tutorial but if you plan on doing anything else with the steam api you need to include these in your “MyProject.h”

    PrivateDependencyModuleNames.Add(“Steamworks”);
    AddThirdPartyPrivateStaticDependencies(Target, “Steamworks”);

    and then include this inside of the header you plan on doing stuff in.
    #include

    This will allow you to call functions like this

    //get the player iID
    uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());

    int Picture = 0;

    // get the Avatar ID using the player ID
    Picture = SteamFriends()->GetMediumFriendAvatar(id);

    Hopefully that will save someone the few hours it took me to figure it out.

Leave a Reply to Οrfeas Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back To Top