Unreal Cloud Code


Previously, we saw how to use Cloud Code in the GameSparks Portal. Now we're going to show you how to use the GameSparks nodes that log Events that have been set up in your Portal.

In this tutorial, the player logs the Get_Pos Event which retrieves the location that was last saved on the player's database. It's useful to use the Test harness and send a default value for the player's initial location - this can be a pawn's initial spawn location in your game. The second part of the tutorial will feature saving the player's pawn location using a key input that logs the Set_Pos Event.

Default Location

Get Event

Set Event

Testing Events

Example Unreal UAssets Cloud code can be downloaded here

Setting up Events

Default Location

Send the pawn's initial spawn location from the editor to the Portal through the Test Harness for the authenticated player to simulate a saved default initial spawn location.

Use the Set_Pos Event to save those three coordinates on the Test Harness after you Authenticate:

Get Event

For this example, call the Get_Pos Event straight after the Player authenticates:

1. Use a GS LogEventRequest node to call Events made in your Portal from the Unreal Engine:

2. After retrieving the POS JSON from the GSData node, you can now retrieve individual values saved inside it. In this case, those values will be the three coordinates x, y, and z:

3. After using the get node to access values within the GSData, you can now receive those values and use them in your gameplay sequence. In this case, this will be setting the players location:

Now we can set up the Set_Pos Event which will take place in the PlayerController. PlayerControllers allow the use of key input.

Set Event

The Set Event will be called in the same way as the Get Event, using the GS LogEventRequest node, except this time you'll be passing through an Attribute which holds the X, Y, and Z values, similar to calling a function with a parameter.

To pass data through the POS attribute, create a LogEventAttributes node and connect it to the Set Object node.


Run your game and test your Events are working correctly in-game. Use the login screen to authenticate your test player.

When your player is authenticated, he'll be teleported to the same location, so you won't see a difference. If you move your pawn, then hit the F key and see the saved print string. Close the game down, then re-launch your game and re-authenticate your player again. Your pawn should teleport to the last location saved against your authenticated Player. This is the basis of saving data persistently using GameSparks. You can use a combination of Events and Cloud Code for nearly unlimited amounts of configuration for your game.