The Unity Gaming Services (UGS) Use Cases are a collection of samples designed to show you how you can use multiple UGS products to solve common game development challenges.
These samples implement typical backend game use cases and game design elements, show how to resolve specific development tasks, and highlight the efficiency you can achieve in your game backend by integrating different UGS packages in your project.
One of these samples is a battle pass — a seasonal reward tier system with a free track and a premium track. This article will explain how this sample works, and how you can implement it in your own game.
This is an ongoing Unity project that you can download and run in the Unity Editor. You can then look at the code to see how various use cases can be addressed by using Unity Gaming Services.
The main goal of this project is to help developers get through the ramp-up process faster by having access to working examples. The code is designed to be easy to read and accessible to developers of all levels of experience.
A battle pass is a popular way to retain players by offering rewards for playing the game, with an additional premium layer to help your game generate revenue in the long term.
This is how it generally breaks down:
For live games, especially multiplayer ones, the server should be the source of truth for most of the players’ data.
This prevents cheating tactics which may allow a player to have an advantage over another, or grant a player items or currencies that would otherwise need to be purchased or earned.
Similarly, in order for seasonal rewards or battle passes to be fair for all players, all data and decisions need to be managed server-side.
In the design of this battle pass sample, Cloud Code (beta) service does most of the heavy lifting in terms of handling the backend infrastructure. Cloud Code allows you to write and run your game logic away from the client.
Other tools used in this sample include Cloud Save (beta), which allows you to store player data to the cloud. In this case, it allows the player’s season progress to be stored in a flat key-value system. A battle pass ownership flag for the current season is also stored with Cloud Save.
Game Overrides (powered by Remote Config), which lets you create personalized in-game player experiences to determine the content of the current season and battle pass tiers.
All of the tier rewards in the battle pass are either currencies or inventory items, which are all managed through Economy (beta). There is also one Purchase set up in Economy for exchanging gems for a battle pass.
As with any game where player data is managed by an online back-end, each player will need to sign in to the game. For this, we're using Authentication (beta). Once the user is signed in, all Unity Gaming Services SDKs will automatically know to send the player's unique ID with every server request.
Here’s how the sample works:
Player state can be obtained and set directly from the client by using Cloud Save, but that shouldn’t be done in this case.
Setting the Cloud Save data directly would make the player data client-authoritative instead of server-authoritative, which opens the door to hacks. By using Cloud Code, we can validate the changes before writing the data to Cloud Save.
Reading the player state directly from Cloud Save could result in getting data from the previous season that has ended. By using Cloud Code, we can automatically reset the player's season state if the season has ended.
By using this sample package, you can implement a fully functional, server-authoritative battle pass with Unity Gaming Services.
Within the Unity Dashboard, you can define your game’s battle pass configuration for a given period of time by setting up a Game Overrides campaign and populating it with JSON values.
A campaign can be for any time span, whether you want to run a special event for an hour, a weekend, or in the case of a Battle Pass, a season lasting months.
The player’s interactions with the game’s UI will send Cloud Code requests to:
Gain Season XP
Claim a reward
Purchase a battle pass
Record the player’s season progress
Return the progress data to the game client
Some of these calls could be done more simply by making direct calls to Economy or Cloud Code. However, with all of these types of requests, you may need to also reinitialize the player’s season progress if the season has changed or if they’re new to the system.
You don’t want the client to decide whether the season data needs to be reinitialized before making each request.
In this battle pass sample’s design, the player’s past rewards are automatically granted if they upgrade to the battle pass (after already claiming free rewards). Because of this, the only way to process a battle pass purchase is via a Cloud Code function.
The function makes the call to Economy to complete a purchase with a cost but no rewards. If that is successful, two things happen:
The battle pass is granted to the player in the form of a value stored in Cloud Save, which only represents the battle pass for the current season.
The player is granted any battle pass rewards for tiers they’ve already claimed.
There are many possible designs for seasonal rewards and battle passes — Unity Gaming Services won’t limit you to this example.
You could use the Unity In-app Purchase package to charge real money for your battle pass instead of in-game currency.
The Unity Gaming Services Use Cases collection includes several other sample packages apart from the battle pass:
Make sure to check back in the GitHub repository as this project will continue to grow to include more use cases for Unity Gaming Services.