Unreal Virtual Goods

Introduction

After following the tutorial Creating a Virtual Good, you are ready to integrate the same functionality into your Unreal Engine Game. You can now:

Here's what we'll cover in this tutorial:

Setting up the Shop Screen

Buying a Virtual Good

Consuming a Virtual Good

Using the Shop


Example Unreal Virtual Goods code can be downloaded here

Using Virtual Goods

Creating the 'Grant Currency' Event

1. Navigate to Configurator > Events and click Add. The Add Event page opens.

2. Create an Event that credits the authenticated player with extra currency.

3. Edit the Event to add an Attribute that will be used to indicate the amount to credit.

This Event will be logged whenever the authenticated player consumes a Gold Coin Virtual Good:

4. Save the Grant currency Event and navigate to Configurator > Cloud Code and under Scripts click Events.

5. Select the GRANT_CURRENCY Event to open the Cloud Code Editor. In the Cloud Code Editor, create a variable that holds the amount being passed in the Event through the CASH Attribute and call it money.

6. Now get the Player object using getPlayer and credit them CURRENCY_1 by the money value:

This is the Cloud Code:

//Get the data passed in from the player
var money = Spark.getData().CASH
//Credit the player with the amount asked for the chosen currency and the reason.
Spark.getPlayer().credit("CURRENCY_1", money, "For clicking the button")


7. Click to Save the Cloud Code you've added to the GRANT_CURRENCY Event.

Setting up the Shop Screen

8. Create a shop screen in your game, with one item for sale - the Gold Coin. The authenticated player is going to have the option to buy and consume gold coins. The player will also be able to see how many Gold Coins they have in their inventory and how much currency they hold in their Currency1 slot.

When the player transitions to the shop screen, the values for the player's Display Name, Currency, and the amount of Gold Coins owned need to be updated.

9. To update the values, request them using GS AccountDetailsRequest node.

10. To retrieve the amount of Gold Coins owned, use the node Get Number dragged from the Account DetailsResponseVirtualGoods port on the AccountDetailsRequest node with the Short Code of the item you're looking for - in this example, it's Gold_Coin:

Clicking to Buy

When the Buy button is clicked, a Gold Coin needs to be purchased.

11. To buy a Virtual Good, call the BuyVirtualGoodRequest node which takes the type of currency, quantity, and the Short Code for the item being bought, which in this case is Gold_Coin.

12. After the player has purchased a Virtual Good, update their details so they are aware of the change.

Clicking to Consume

Check to see if the player has Gold Coins to consume.

13. If the player has enough Gold Coins, call the GS ConsumeVirtualGoodRequest node, which takes a quantity and the Short Code of the Virtual Good. The ConsumeVirtualGood Event automatically decrements the overall quantity owned in the player's inventory.

14. After the Gold Coin is consumed, log the Grant_Currency Event to accredit the authenticated player with a value of 1 passed through the CASH Attribute.

Using the Shop

If the authenticated player uses the shop they should be able to buy and consume the Gold Coin Virtual Good and see their information update correctly.

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here