Satori Unity Client Guide #
This client library guide will show you how to use the core Satori features in Unity.
Prerequisites #
Before proceeding ensure that you have:
- Access to Satori server instance
- Installed the Satori Unity SDK
Full API documentation #
For the full API documentation please visit the API docs.
Installation #
The client is available from the:
The Nakama.unitypackage
contains all source code and DLL dependencies required in the client code.
After downloading the file:
- Drag or import it into your Unity project
- Set the editor
Api Compatibility Level
setting to .NET Standard 2.1 (from the Edit -> Project Settings -> Player -> Other Settings -> Configuration menu). - From the Assets menu create a new C# script and a client object
Alternatively, you can checkout a specific release or commit by adding the following to the manifest.json
file in your project’s Packages
folder:
"com.heroiclabs.nakama-unity": "https://github.com/heroiclabs/nakama-unity.git?path=/Packages/Nakama#<commit | tag>"
Updates #
New versions of the Satori Unity Client and the corresponding improvements are documented in the Release Notes.
Unity / .NET SDK Differences #
In general, this client guide can also be used in conjunction with the Satori .NET SDK with a few minor differences which are outlined below.
Logging #
Logging to the console in this guide uses the Unity specific Debug.LogFormat
method. In the .NET SDK use:
|
|
Saving/Loading Data #
This guide makes use of Unity’s built in PlayerPrefs
to store and load data. When using the .NET SDK you are free to use whatever data storage/retrieval method you choose, such as saving directly to disk.
Getting started #
Learn how to get started using the Satori Client to manage your live game.
Satori client #
The Satori Client connects to a Satori Server and is the entry point to access Satori features. It is recommended to have one client per server per game.
To create a client pass in your server connection details:
|
|
Configuring the request timeout length #
Each request to Satori from the client must complete in a certain period of time before it is considered to have timed out. You can configure how long this period is (in seconds) by setting the Timeout
value on the client:
|
|
Authentication #
Authenticate users using the Satori Client via their unique ID.
When authenticating, you can optionally pass in any desired defaultProperties
and/or customProperties
to be updated. If none are provided, the properties remain as they are on the server.
|
|
When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session
object.
Session lifecycle #
Sessions expire after five (5) minutes by default. Expiring inactive sessions is good security practice.
Satori provides ways to restore sessions, for example when players re-launch the game, or refresh tokens to keep the session active while the game is being played.
Use the auth and refresh tokens on the session object to restore or refresh sessions.
Store these tokens in Unity’s player preferences:
|
|
Restore a session without having to re-authenticate:
|
|
Automatic session refresh #
The Unity client library includes a feature where sessions close to expiration are automatically refreshed.
This is enabled by default but can be configured when first creating the Satori client using the following parameters:
AutoRefreshSession
- Boolean value indicating if this feature is enabled,true
by defaultDefaultExpiredTimespan
- The time prior to session expiry when auto-refresh will occur, set to 5 minutes be default
Manually refreshing a session #
Sessions can be manually refreshed.
|
|
Ending sessions #
Logout and end the current session:
|
|
Experiments #
Satori Experiments allow you to test different game features and configurations in a live game.
List the current experiments for this user:
|
|
You can also specify an array of experiment names you wish to get:
|
|
Feature flags #
Satori feature flags allow you to enable or disable features in a live game.
Get a single flag #
Get a single feature flag for this user:
|
|
You can also specify a default value for the flag if a value cannot be found:
|
|
Specifying a default value ensures no exception will be thrown if the network is unavailable, instead a flag with the specified default value will be returned.
Get a single default flag #
Get a single default flag for this user:
|
|
Similar to the GetFlagAsync
method, you can also provide a default value for default flags:
|
|
Specifying a default value ensures no exception will be thrown if the network is unavailable, instead a flag with the specified default value will be returned.
Listing identity flags #
List the available feature flags for this user:
|
|
Listing default flags #
List all default feature flags:
|
|
Events #
Satori Events allow you to send data for a given user to the server for processing.
metadata
field is 4096
bytes.Sending single events #
|
|
Sending multiple events #
|
|
Live events #
Satori Live Events allow you to deliver established features to your players on a custom schedule.
List all available live events:
|
|
Identities #
Satori Identities identify individual players of your game and can be enriched with custom properties.
List an identity’s properties #
|
|
Update an identity’s properties #
|
|
You can immediately reevaluate the user’s audience memberships upon updating their properties by passing recompute
as true
:
|
|
Identifying a session with a new ID #
If you want to submit events to Satori before a user has authenticated with the game server backend (e.g. Nakama) and has a User ID, you should authenticate with Satori using a temporary ID, such as the device’s unique identifier or a randomly generated one.
|
|
You can then submit events before the user has authenticated with the game backend.
|
|
The user would then authenticate with the game backend and retrieve their User ID.
|
|
Once a user has successfully authenticated, you should then call IdentifyAsync
to enrich the current session and return a new session that should be used for submitting future events.
|
|
Note that the old session is no longer valid and cannot be used after this.
Deleting an identity #
Delete the calling identity and its associated data:
|
|
Messages #
Satori integrates with various messaging services to send messages to users via messages schedules. You can list a user’s messages, update a message’s status, and delete a message.
List messages #
List all messages for the calling identity:
|
|
Update message status #
Update the status of a message:
|
|
Delete message #
Delete a scheduled message:
|
|