Starter packs are one-time deals that grant new players additional resources at a discount. Starter packs improve the onboarding process and boost engagement early, and can also help convert new players to paying users.
This sample demonstrates how to create a one-time starter pack deal in your game that a player can purchase with in-game currency.
To see this use case in action:
- In the Unity Editor Project window, select Assets > Use Case Samples > Starter Pack, and then double-click
StarterPackSample.unity
to open the sample scene. - Enter Play Mode to interact with the use case.
When the scene loads, the StarterPackSceneManager.cs
script performs the following initialization tasks:
- Initializes Unity Gaming Services.
- Signs in the player anonymously using the Authentication service. If you’ve previously initialized any of the other sample scenes, Authentication will use your cached Player ID instead of creating a new one.
- Retrieves and updates currency balances from the Economy service for that authenticated user.
In this example, the starter pack costs 10 Gems. For demonstration purposes, this scene provides a button that grants the player 10 Gems each time it is clicked, which ensures enough currency to test the purchase. When you click the Give 10 Gems button, the following occurs:
- The button's
OnClick
method calls theStarterPackSceneManager
script'sOnGiveTenGemsButtonPressed
function. TheOnGiveTenGemsButtonPressed
function calls the Economy service to add 10 Gems to the player's balance, and then the UI code updates the player's resources in the Currency HUD.
Note: that the purchase button is temporarily disabled while the currency balance updates.
When you click the button to buy the starter pack having 10 or more Gems, the player consumes 10 Gems in exchange for the resources offered in the pack. The following occurs:
- The button's
OnClick
method calls theStarterPackSceneManager
script'sOnBuyButtonPressed
function, which sends a request to the Cloud Code service to execute thePurchaseStarterPack
script. - This
PurchaseStarterPack
script queries the Cloud Save service to verify that the player has not yet claimed the deal, and then initiates a purchase directly with the Economy service. - If the player has not claimed the deal, the script calls the Economy service to subtract 10 Gems from the player's balance, and then sends an update to the Cloud Save service directly to set a flag that this player has now claimed the deal.
- The UI code updates the player's resources in the Currency HUD.
The purchase button also updates to indicate that the offer has already been claimed. At this point, you cannot purchase additional starter packs unless you click the Reset Starter Pack button, no matter how many Gems you have.
After purchasing a starter pack, the player cannot purchase another one unless they reset their game save. To illustrate this, this scene provides a button to reset the flag so the player can purchase it again. When you click the Reset Starter Pack button, the following occurs on the backend:
- The button's
OnClick
method calls theStarterPackSceneManager
script'sOnResetPlayerDataButtonPressed
function, which sends a request to the Cloud Code service to execute thePurchaseStarterPack
script. - The script sends an update to the Cloud Save service directly to set a flag that this player has not yet claimed the deal.
- The UI code re-enables the Starter Pack purchase button.
To replicate this use case, you need the following Unity packages in your project:
Package | Role |
---|---|
Authentication | Signs in the user anonymously to keep track of their data server-side. |
Cloud Code | Stores important validation logic on the server side. |
Cloud Save | Stores small pieces of data, such as a flag that indicates if the user has claimed their starter pack. |
Economy | Retrieves the starting and updated currency balances at runtime. |
Deployment | The Deployment package provides a cohesive interface to deploy assets for Cloud Services. |
To use these services in your game, activate each service for your Organization and project in the Unity Dashboard.
To replicate this sample scene's setup in your own Unity project, we need to configure the following items:
- Cloud Code scripts
- Economy items
There are two main ways of doing this, either by using the Deployment package, or by manually entering them using the Dashboard. We recommend the usage of the Deployment package since it will greatly accelerate this process.
Here are the steps to deploy configuration using the Deployment package:
- Open the Deployment window
- Check in
Common
andStarter Pack
- Click
Deploy Selection
This will deploy all the necessary items.
The Dashboard enables you to edit manually all your services configuration by project and environment. Here are the details necessary for the configuration of the current sample.
Publish the following scripts in the LiveOps dashboard:
Script | Parameters | Description | Location in project |
---|---|---|---|
PurchaseStarterPack |
None | Queries the Cloud Save service to verify that the player has not yet claimed the deal, before initiating a purchase directly with the Economy service. | Assets/Use Case Samples/Starter Pack/Config as Code/PurchaseStarterPack.js |
ResetStarterPackFlag |
None | Resets the starter pack flag to indicate the current player has not yet claimed the deal. | Assets/Use Case Samples/Starter Pack/Config as Code/ResetStarterPackFlag.js |
Configure the following resources in the LiveOps dashboard:
Item | ID | Type | Description |
---|---|---|---|
Gem | GEM |
Currency | The cost of the Starter Pack |
Coin | COIN |
Currency | A reward from the Starter Pack |
Pearl | PEARL |
Currency | A reward from the Starter Pack |
Sword | SWORD |
Inventory Item | A reward from the Starter Pack. |
Also, configure the following Virtual Purchase resource in the LiveOps dashboard:
Item | ID | Type | Cost | Reward |
---|---|---|---|---|
Starter Pack | STARTER_PACK_PURCHASE |
Virtual Purchase | 10 Gems | 100 Coins + 1 Sword + 10 Pearls |