Leaderboard and achievements (Google Play)

Hello community,

This is done all in blueprint.

I am very beginner at unreal engine 4 and making games at all. So here I am almost at completion of my first google play game and I encounter the boss known as leaderboard and achievements.

I was not able to do it and did not find any simple guide to help (Yes, they do have documents regarding them). Also, the Tappy chicken and Unreal match3 helped me but, they were complex for me as a beginner. But, through trial and error I finally was able to implement leaderboard and achievement eventually.

So, i thought why not just make a post about how I did it so that anyone else facing the same issue can hopefully solve theirs easily.

Assuming you have and know how to implement save system for your variables, and you have the set up for google play in the project settings.

For save game - BP Time Attack Racer: Save Game System | 10 | v4.8 Tutorial Series | Unreal Engine - YouTube

For google play setup - Google Play Setup - Mobile - Unreal Engine Forums

Leaderboard set up document - Using Google Play Services Leaderboards in Unreal Engine Projects | Unreal Engine 5.0 Documentation

Achievement set up document - Using Google Play Achievements in Unreal Engine Projects | Unreal Engine 5.0 Documentation

Here I have a basic save and load system for a “Best score” variable i.e an integer. And I want leaderboard and achievements based on that.

Now, FIRST STEP: LOGIN

Show External Login UI.png

I have this node in my main Gamemode BP. So that, On Event begin play it is firing. What this basically does is logs you/your player to the online subsystem.

The “On Success” and “On Failure” are attached to the next node. What they basically ensure is that the flow does not move while the log in is taking place.

SECOND STEP: LEADERBOARD

I have my leaderboard set up INSIDE my player blueprint as it is where my variable “Best score” is and so is my “Save and Load” logic.

In leaderboard we have 2 important nodes, i.e “Write Leaderboard Integer” and “Read Leaderboard Integer.”

In this, I am making a custom event that checks if the score that is made in the game session is greater than the saved best score and if yes, set that to the best score. This function executes every time the player dies or game gets over.

Now, using the “Write Leader board Integer” node I plug the value of “best score” into the stat value. And in the stat name we simply have the name of our LEADER BOARD that we gave in the “project settings.”

This node posts the value of the stat to the online subsystem if connection was made in step one.

Now, that we have written our score, its time to read it.

I am firing this “Read Leaderboard Integer” on “Event begin play”. This node reads the value from the online subsystem.

Now, a player might have played the game on a different device and made a higher score which would be more than the score in his own device in his local save. So, i’m taking the value of in the leaderboard and comparing that to the best score.

If leaderboard value is bigger then, i’m setting that to be my best score.

The print function is simply for checking purposes and On success and On failure have the same functionality.

AND VOLA! Leaderboard working!

THIRD STEP: ACHIEVEMENTS -

A) First, make variable arrays for your achievements. Still in MY PLAYER BP.

e948dcb2580572d4482c38d849443bc294602696.jpeg

The “achievement value” is of type float and contains elements corresponding to the number of achievements. Their corresponding values are the values at which you want achievements to unlock.

The “achievement names” is of type name and contains the elements corresponding to the number of achievements AND THE VALUE OF THE NAMES IN ARRAY are the NAMES that you set in the Project settings for your achievements.

The “achievement progress” is also of type float and contains elements corresponding to the number of achievements. Their values are left at default zero.

**It is very important that each index in the arrays are relative to each other. For ex - My first achievement is - “Basic player”, unlocked when best score is “5”
and say they are at index 0 i.e in “achievement names” array at 0 i have “Basic player” value and in “achievement value” at 0 I have “5” **

B) Now, moving to Gamemode BP,

CacheAcievments.png

The “cache achievement” node simply fetches and caches achievement data from the online subsystem.
**It is in flow after the “Show external Login UI” **. The “On success” and “On failure” have the same functionality.

C) Moving back to player BP.

In the image, I have made a custom event called UpdateAchievementProgress.

This is connected to a “FOR EACH LOOP” which is pulling from our “Achievement value” array.

Now, I’m taking the Array element, which is the basically the value we gave. And taking our best score and converting it to Float.

Then dividing our best score by our achievement value at that index and then multiplying it by 100 and feeding that to item in set array element. Which is targeted to “Achievement progress” array.

For index we use the same index as currently being used by our FOR EACH LOOP.

Next, we are using the “Write achievement progress” node. We are getting the “Achievement progress” array value at the index and feeding it to progress and also fetching the achievement name from our array at that index and feeding it to Achievement name.

This UpdateAchievementProgress function is run every time we score check turns to be true.

D) And Finally

Another custom event “GetAchievmentsInfo” is made.

In this, using FOR EACH LOOP with “Achievement name” as target. We are getting achievement info using “Get Cached Achievement Progress”

The array element will be our achievement ID.

Using Found ID we branch and if true we set the array elements of our “Achievment progress” array and for index we use the FOR EACH loop array index. For Item we use progress from “Get Cached Achievement Progress”.

THIS “GetAchievmentsInfo” is run on every event begin play in the my player BP

AND DONE! ACHIEVEMENTS AND LEADER BOARDS are set up!

All that needs to be done now is to make a button on UMG or HUD to open them.

NOTE - This might not be the best guide but I was having trouble finding one so I made it. And their might be some problems in it which I would really appreciate someone points out. Hopefully its all good. Thank you for reading :stuck_out_tongue:

There might be many grammatical mistakes or typing mistakes in the post so I apologize for that. This is my first time writing such a big thread. It took me 2 hours.

Hopefully, I helped someone.

3 Likes

Hello Shobhitthackar, excellent Guide for implementing Google OSS, possibly sheds some light on implementation for other OSS. Thank you for the contribution.

That makes my 2 hours worth it! Thanks! :smiley:

Hi, How can i get the highest score of all players ?
Because ReadLeaderboarInteger only gets the highest score of the one is playing, or am i missing something?
Thank you.

Hello, thanks for this tutorial ! But I don’t understand why this not showing the highscore :frowning:


https://forums.unrealengine.com/core/image/gif;base64
​IT DOESN’T WORK IT JUST DOESN’T!!!
Been having this problem for 3 days and the nodes just ALWAYS results in failed… I have 1 achievement on Google Console and it is published, in Unreal project settings I added 1 element and I’ve placed a name that “Used solely in Unreal Project” and the ID from Google Console… I did EVER YTHING right and it still gives me a Failure!!!