Skip to content

Native games

When the launcher starts a native game (the program you named as the executable when uploading the build), it sets three environment variables:

Variable Meaning
SPAWNLE_TICKET The player’s game ticket (gt_…).
SPAWNLE_API The API to call, e.g. https://api.spawnle.com.
SPAWNLE_GAME Your game’s id.

If SPAWNLE_TICKET is missing, the game was not started by Spawnle (you ran it yourself while developing). Fall back to offline behaviour.

Send the ticket as a bearer token to the SDK routes:

GET /v1/sdk/me HTTP/1.1
Host: api.spawnle.com
Authorization: Bearer gt_9f2c…
using System;
using UnityEngine;
using UnityEngine.Networking;
public class Spawnle : MonoBehaviour
{
string ticket = Environment.GetEnvironmentVariable("SPAWNLE_TICKET");
string api = Environment.GetEnvironmentVariable("SPAWNLE_API") ?? "https://api.spawnle.com";
[Serializable] class Me { public string handle; public string display_name; public int level; }
System.Collections.IEnumerator Start()
{
if (string.IsNullOrEmpty(ticket)) yield break; // not started by Spawnle
var request = UnityWebRequest.Get(api + "/v1/sdk/me");
request.SetRequestHeader("Authorization", "Bearer " + ticket);
yield return request.SendWebRequest();
var me = JsonUtility.FromJson<Me>(request.downloadHandler.text);
Debug.Log($"Hi {me.display_name}!");
}
}

The ticket only opens the SDK routes for this player in this game, but treat it like a password: do not log it, do not show it, and send it only to SPAWNLE_API or to your own server.

Tickets last 24 hours. A game session longer than that should handle 401 unauthorized by asking the player to restart the game from Spawnle.