Unleash the power of the cloud by integrating Unity with GameSparks


Are you working with Unity to build games? Unleash the power of the cloud by integrating Unity with GameSparks’ complete Games-as-a-Service platform.  Integration is straight forward – there is an SDK.  The following post explains where to get it and how to integrate it.  Our service is completely free up until you hit 10,000 MAUs.

Download the SDK

The GameSparks Unity3D SDK is provided as a standard unity package and can be downloaded here. There are 2 versions available. One for unity 4.0+ without WP8 and WinRT support, and one for Unity 4.3 with WinRT and WP8 support.

Create a new Unity project


Unity and GameSparks


Import the SDK you downloaded


Unity and GameSparks

After you have selected the file you will be presented with the following screen, ensure all items are selected and click Import.

Unity and GameSparks

Your project should now contain the folder Assets/GameSparks

Unity and GameSparks


Configure the SDK

To configure the SDK for use with your game, select “GameSparks -> Edit Settings” from the menu bar

(If the GameSparks menu item is not visible click another one and it will appear, this is a nuance of menu items in Unity)

Unity and GameSparks


You will then be presented with an Editor pane that allows you to configure the SDK for your needs.

Unity and GameSparks


Populate the pane with the following settings:

Api Key – The “GameSparks Api Key” value from the Overview Menu in the portal Configurator

Api Secret – The “GameSparks Api Secret” value from the Overview Menu in the portal Configurator

Development Build – Select this option when you want to run the SDK against the unpublished configuration

Debug Build – Select this option to get extended debugging out of the SDK (useful for support purposes)


Testing Your Configuration

Click the “Test Configuration” button in the GameSparks settings editor. This will open the test harness (you will be prompted to save your current scene). You should see JSON messages being sent and received by Unity from the service.

Unity and GameSparks


Authenticating Against The Service

On the first run, you will see the label “NOT AUTHENTICATED”, to send requests to the platform, you need to be authenticated. There are a number of requests that can authenticate you, these are:

AuthenticationRequest – User to authenticate using details previously provided in a RegistrationRequest

DeviceAuthenticationRequest – Uses the unique identifier for the device to create an anonymous user, the unity SDK deals with all the parameters required for this

FacebookConnectRequest – Uses a facebook authentication token to register and or authenticate with the platform

RegistrationRequest – Allows a new user to be created with a username & password.

The test UI contains a button to do a device authentication. Click this button and the current player will be authenticated.

Unity + GameSparks


Authentication Caching

The SDK stores the auth token from the platform and uses it the next time it connects. This allows the device to remain logged in between application invocations. The authToken from the changes ever time the user connects, and the SDK manages this for you.

You can call the GameSparkssApi.isAuthenticated() method to determine if the current player is authenticated or not


Adding the SDK to your own game.

The GameSparksUnity class needs to be added to one of your own components within your game. The SDK is set to DontDestroyOnLoad, so it only needs to be added once. We reccomend you add this in the first loaded scene of your game to allow analytics to be recorded as soon as possible. The SDK manages it’s lifecycle internally, and will manage network disconnects and reconnects automatically, allowing you to call the GameSparks statics methods anywhere in your code.


Sending Requests to GameSparks.

The API allows you to make either blocking, or non-blocking API calls to the GameSparks platform. Blocking calls will wait until the response is returned from the platform, where as non blocking calls allow you to supply a callback delegate to be executed when the response is returned. Non blocking calls are executed on the main game thread. If you want the supplied delegate to be run on a background thread.

A number of convenience methods exist in the Api to allow you to make requests. These methods return a GameSparksSender object, that has a blocking send() method and a non blocking sendAsync(Action) method. A sendBackground(Action) method exists if you want the delegate to run on a background thread.

Blocking Example




Non Blocking Example

The call back method for async calls needs to take a single parameter of IDictionary<string,object> and can be either a pre defined method, or an anonymous delegate. The delegate will be executed on the main game thread







delegate(IDictionary<string, object> response) {

HandleLog(response[“@class”].ToString(), null, LogType.Log);




Registering Event Handlers for GameSparks Messages

The GameSparks platform sends asynchronous messages to clients outside of requests and responses. To capture these you needs to register your event handler for these messages. The example form the TestUI is as follows:









void Start(){

GameSparksApi.GameSparksMessageReceived  += HandleGameSparksMessageReceived;



void HandleGameSparksMessageReceived (object sender, GameSparksMessageReceivedEventArgs e)


Debug.Log(“MSG” + e.Message);



Determining the availability of the SDK.

Using the SDK you can either query the SDK to determine if it’s connected and initialised. To query the current state of the SDK:

1bool available = GameSparksApi.isAvailable


To register a callback to listen to availability events.




void Start(){

GameSparksApi.GameSparksAvailable += HandleGameSparksAvailable;


If you have any further questions, please email customer services at: info@gamesparks.com

  • Eliseo Viola

    The Download link wont work.

  • Vikas Singh

    Hi, I am getting a “Not Available”, what could possibly be wrong

  • Dylan Hunt

    ^ Obsolete information — The entire hierarchy seems to have changed. Their main doc has more up-to-date info, although scarse – they promised to update this year (2016).

    • Ellie Lawson

      Hi Dylan, as promised, our documentation is currently going through a very large revamp. Documentation will be much ‘fuller’ and we will also update this post for you.

Who uses GameSparks?