In this tutorial, I’ll be demonstrating how to set up achievements for Android games in Unreal Engine 4 using Blueprints.
First you’ll have to actually create the achievements.
Go into your Android Developer Console, located here.
Go under Game Services > Your Game > Achievements, then click on the Add New Achievement button near the top.
The options you’ll find in here are all pretty self-explanatory, and mostly just affect how the achievement will appear on the menu in game. So a detailed breakdown here would be unnecessary.
Create the achievement, and take note of the ID code listed to the right of it on the achievement screen from the previous images.
For the next step, you need to go into your UE4 project. click the Edit tab, and open Project Settings.
From here, go down to Platforms > Android. From inside this tab, go down to Google Play Services, then Achievement Map.
Click the + to add a new achievement. Give it a name to identify it, as well as the ID code noted from your developer console earlier.
The name is what you will use inside of blueprints to call out your achievement. The ID code is tied to this, and used by Google Play Services externally to identify it. Basically, the name is used to encapsulate the ID code and give it an easy-to-read form.
Next, go into the main blueprint handling your achievements, such as the Game Mode.
You’ll need to create three variable arrays; one containing the names of all your achievements. One containing the integer value needed to unlock the achievement (such as 100, if the achievement requires 100 points to unlock). And one used to store the float value percent of progress made on each achievement. This last one should have an element for every achievement, though the actual value in each element can remain as 0.
Make sure all of the element numbers line up. Such that, for example, the 0 element in each array represents a value of the same achievement.
You now need a function to call whenever you need to check the progress of any achievements. So create a new function in your blueprint, and name it something like “Check Achievements”.
Inside the function, you first need to pull in the values you intend to check against your achievements. Such as the number of points earned. A Save is a convenient place to pull values from if you’re not checking against only specific achievements. If you build the function properly, such as through a blueprint instance, then the function can simply take the values you want to check as an input, and then output them inside to check against. For simplicity, I’ll be using a Save.
After that you need to create a For Loop. The size of the loop should be equal to the number of achievements you intend to check. To determine which achievements are checked, the loop will be comparing its index number against the element numbers of your achievements.
For example, if you need to check the progress of achievements found between elements 5 and 10, then the loop should run between the indexes of 5 and 10.
From here, you need to grab the actual values you want to check, such as points gained. Using the loop index, you will also grab the value to compare against stored inside of your Achievement Value array.
Divide the point value by the maximum value inside the array. This will give you the percentage of progress you’ve made towards that achievement. You then need to multiply this by 100, since Google Play reads the percentage as between 0 and 100, rather than between 0 and 1.
Clamp this value between 0 and 100 to prevent errors, then set the value of the respective element inside the Achievement Progress array to this amount. If the value reaches 100, the achievement will be unlocked.
Finally, create a Write Achievement Progress node (featured above in the first blueprint screenshot), and plug in all of your arrays. This will update the achievement on Google Play.
Activating the Show Platform Specific Achievements Screen node will display the Google Play achievement screen.