Preparing Sphere Kit

Initialise Sphere Kit to be used throughout your game.

Sphere Kit uses a static class model, where the CoreServices class is available throughout your game. This means that you can access Sphere Kit services from any part of your code.

CoreServices controls the essentials of Sphere Kit functionality, including initialisation, authentication and achievements. To prepare the Sphere Kit CoreServices class, it is recommended to create a game object that is on the launch scene (i.e. the first scene that renders when your game opens).

1

Create an empty game object

In your launch scene, create a new game object by selecting the Create Empty option.

2

Add a script to initialise Sphere Kit

  1. Create a new script for your empty game object. We'll call it SphereKitScript in this example.

  1. Replace the contents of your script with the following code (replace SphereKitScript with the name of your script).

SphereKitScript.cs
using SphereKit;
using UnityEngine;

public class SphereKitScript : MonoBehaviour
{
    private async void Awake()
    {
        await CoreServices.Initialize();
    }
}

The Awake() method is called when the object is loaded, and the CoreServices class is initialised by calling its Initialize() method.

The terms async and await are important. await makes the function pause until the method call completes, allowing other functions to run in the meantime. This way, the game doesn’t freeze during a server task. async indicates that the function should be run concurrently and its output can be awaited.

Congratulations 🎉 Now, you can use CoreServices in any script in your game!

Last updated