Unreal Leaderboards

Introduction

If you've followed the tutorial for making an Event and a Leaderboard, then for this tutorial you only need to call your Event.

Here's an overview of what we'll cover in this tutorial:

GameSparks Message Listeners

Calling the Event


Example Unreal Leaderboard code can be downloaded here

Setting up the Message Listener

l

1. First, we'll need to create a GSMessageListeners component (highlighted in red) in the Game Mode:

l

The GSMessageListeners component is an extremely useful tool, which allows you to intercept messages from the Portal to your authenticated player, then break those messages down and use them in your sequences.

2. Here we're going to demonstrate the use of one message type interception by using the event OnNewHighScoreMessage. This can be dropped into the Event Graph after clicking the GSMessageListeners component:

l

And accessing its Events (highlighted in Green):

l

Once we drop the Event in, we can break the message down and access data that is useful to us.

For this tutorial, we'll be retrieving the name of the Leaderboard to inform the player on which Leaderboard they have achieved a High Score.

Setting up the Event Call

Once the Listener is ready, we can call the Leaderboard_Score Event from anywhere we wish to upload the final score to. For this tutorial, we've placed it right after our game countdown reaches zero and the points we collected during the game are uploaded to the Leaderboard. If a new High Score is achieved for the currently authenticated player, a message will be sent to notify them.

Now, execute the Event that was previously set up on the Portal using GS LogEventRequest:

l

Testing

Finally, you can play the game.

Here you can authenticate, play the game, and, if you beat the High Score, you'll receive a message saying you did so:

l

Retrieving Leaderboard Entries

One way to retrieve entries from a Leaderboard is the LeaderboardDataRequest. The LeaderboardDataRequest retrieves a list of entries from the top of the Leaderboard to a stated number set in the Entry Count input. For our example we'll be using this request.

Another useful request is AroundMeLeaderboardRequest, which retrieves a number of entries above and below the current player's entry in a specified Leaderboard. Both requests return Leaderboard entry structures that can be used in the same way.

For our example, we'll be calling a LeaderboardDataRequest and looping through every entry in the 'Data' array.

l

We'll get the Rank, Username, and our custom value used to rank the entries 'SCORE'.

l

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here