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.
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:
- Seasonal reward configuration data is sent from Game Overrides to the client, and is also available in Cloud Code (read only). The game client will use this data to determine the UI. Cloud Code will use this data to determine which rewards to grant a player that claims a valid reward tier.
- Cloud Save is used to track the player’s progress through the reward tiers. The player will have an array of mutually exclusive tier states with three possible values: Locked, Unlocked, or Claimed.
- Cloud Save also stores a value indicating whether the player has purchased the battle pass for the current season.