Starter Packs

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.

Prerequisites

To use this sample use case, you must download and install the UGS Use Cases project in your Unity project.

Overview

To see this use case in action, open the samples menu and navigate to Starter Packs. To open this scene directly and interact with the use case:

  1. In the Unity Editor Project window, select Assets > Use Case Samples > Starter Packs, then double-click StarterPackSample.unity to open the sample scene.
  2. Press Play to enter Play mode.

Initialization

The StarterPackSceneManager.cs script performs the following initialization tasks in its Start function:

  1. Initializes Unity Gaming Services.
  2. 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.
  3. Retrieves and updates the player's currency balances from the Economy service.

Functionality

Give 10 Gems

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:

  1. The button's OnClick method calls the StarterPackSceneManager.cs script's OnGiveTenGemsButtonPressed function.
  2. The OnGiveTenGemsButtonPressed 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.

Purchase starter pack

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:

  1. The button's OnClick method calls the StarterPackSceneManager.cs script's OnBuyButtonPressed function, which sends a request to the Cloud Code service to execute the PurchaseStarterPack.js script.
  2. This PurchaseStarterPack.js 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.
  3. 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.
  4. 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.

Reset Starter Pack

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:

  1. The button's OnClick method calls the StarterPackSceneManager.cs script's OnResetPlayerDataButtonPressed function, which sends a request to the Cloud Code service to execute the PurchaseStarterPack.js script.
  2. The script sends an update to the Cloud Save service directly to set a flag that this player has not yet claimed the deal.
  3. The UI code re-enables the Starter Pack purchase button.

Setup

Requirements

To replicate this use case, you'll need the following Unity packages in your project:

PackageRole
AuthenticationSigns in the user anonymously to keep track of their data server-side.
Cloud CodeContains important validation logic server-side.
Cloud SaveStores small pieces of data, such as a flag that indicates if the user has claimed their starter pack.
DeploymentProvides a cohesive interface to deploy assets for Cloud Services.
EconomyRetrieves and updates the player's currency balances at runtime.

To use these services in your game, activate each service for your Organization and project in the Unity Cloud Dashboard.

Unity Cloud services configuration

To replicate this sample scene's setup in your own Unity project, configure the following items:

  • Cloud Code scripts
  • Economy items

To configure these items you can use the Deployment package, or manually enter them using the Unity Cloud Dashboard. The recommended best practice is to use the Deployment package as it greatly accelerates this process.

Using the Deployment package

To deploy configurations using the Deployment package:

  1. Open the Deployment window.
  2. Check in Common and Starter Pack.
  3. Click Deploy Selection.

This deploys all the necessary items.

Using the Unity Cloud Dashboard

You can use the Unity Cloud Dashboard to manually configure your services by project and environment. Refer to the following sections to configure this sample.

Cloud Code

Publish the following scripts in the Unity Cloud Dashboard:

ScriptParametersDescriptionLocation in project
PurchaseStarterPackNoneQueries 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/Cloud Code/PurchaseStarterPack.js
ResetStarterPackFlagNoneResets the starter pack flag to indicate the current player has not yet claimed the deal.Assets/Use Case Samples/Starter Pack/Cloud Code/ResetStarterPackFlag.js

Note: The Cloud Code scripts included in the Cloud Code folder are local copies because you cannot view the sample project's dashboard. Changes to these scripts do not affect the behavior of this sample because they are not automatically uploaded to the Cloud Code service.

Economy

Configure the following resources in the Unity Cloud Dashboard:

Resource typeResource nameIDDescription
CurrencyGemGEMThe currency cost of the Starter Pack
CurrencyCoinCOINA currency reward from the Starter Pack
CurrencyPearlPEARLA currency reward from the Starter Pack
Inventory ItemSwordSWORDAn inventory item reward from the Starter Pack.