Description
A progressive reward system encourages daily engagement by granting players increasingly valuable items as they log in on consecutive days. This example uses a three-tier reward table: players who reach 2-, 5-, and 7-day login streaks each receive a different item grant. All streak logic runs in CloudScript, which acts as the authoritative server. The client cannot manipulate streak counts or grant timing—everything is validated and written by the server.How it works
Authenticate
The client calls an authentication method (for example,
LoginWithCustomID) to obtain a valid session ticket.Call the CheckIn CloudScript
Immediately after login the client calls
ExecuteCloudScript with FunctionName: "CheckIn".CheckIn reads the player's tracker
CheckIn calls server.GetUserReadOnlyData with the key CheckInTracker to retrieve the player’s current streak length and the timestamp of their next eligible grant.- If the key does not exist (first-ever login), a new tracker record is created, written back to PlayFab, and an empty result is returned with a message to log in tomorrow.
Validate streak eligibility
The script checks three conditions:
- The current time is past
NextEligibleGrant(at least one day has passed). - The current time is less than
NextEligibleGrant + 1 day(the player has not skipped a day, which would break the streak).
Increment the streak and advance the grant window
LoginStreak is incremented by 1. NextEligibleGrant is advanced by one day. The updated tracker is written back with server.UpdateUserReadOnlyData.Look up the reward table
CheckIn calls server.GetTitleData with the key ProgressiveRewardTable to retrieve the JSON reward table stored in Title Data.Select and grant the reward
The script iterates over the reward table entries. For each entry whose
MinStreak threshold is at or below the player’s current streak, the corresponding Reward item ID is selected. The highest-matching reward is then granted to the player via server.GrantItemsToUser.Testing tier 2 and tier 3 rewards without waiting requires using the Admin API to directly set the player’s
CheckInTracker data to a value that represents the appropriate streak length and next-grant timestamp.PlayFab building blocks
- Accounts — player authentication and session management
- Player ReadOnly Data — per-player
CheckInTrackerstoring streak length and next-grant timestamp - Title Data —
ProgressiveRewardTablemapping streak thresholds to item IDs - Catalog — items to be granted as rewards
- Virtual Currency — Gems (GM) used as an optional reward currency
- CloudScript —
CheckInhandler containing all streak and grant logic
Setup
Create the Gems virtual currency
In Game Manager, go to Economy > Currencies and select New Currency. Enter:
Select Save Currency.
| Property | Value | Detail |
|---|---|---|
| Code | GM | Abbreviation for the Gems currency |
| Name | Gems | Display name |
| Initial Deposit | 5 | Starting balance for every new player |
Upload the catalog
Go to Economy > Catalogs and select Upload JSON. Select
Catalog.json from the PlayFab-JSON folder of this recipe.Upload the title data
In Game Manager, go to Content > Title Data. Under Title Data, select Upload JSON and provide
TitleData.json. This file contains the ProgressiveRewardTable key that maps login streaks to item grants.The CloudScript
TheCheckIn handler is the core of this recipe. Key sections are annotated below.
Helper functions
Helper functions
Running the example
- Unity 3D
- JavaScript
Install the PlayFab Unity SDK
Download the PlayFab Unity 3D SDK and import it into a new or existing Unity project.
Import the recipe package
Import
ProgressiveRewardsRecipe.unitypackage from the Example-Unity3d folder (or download it from the PlayFab-Samples GitHub repo).Open the scene
In the Project window, open Assets > PlayFab Recipes > ProgressiveRewards > Scenes and add the ProgressiveReward scene to your Hierarchy.
Set your title ID
Select the Main Camera under the ProgressiveRewards scene. In the Inspector, set Play Fab Title Id to your PlayFab title ID.
