Godot 4: the InstaPlay SDK for Godot games
The addons/instaplay 1.3.0 add-on gives Godot 4.3+ games with Web export the whole InstaPlay SDK 1.4
in GDScript (including the player token for your own server, player changes, ads and sign-in from the
game), plus an export HTML
shell that includes the SDK and reports engine loading progress.
Installation
- Download the add-on: instaplay-godot-addon-1.3.0.zip
(size and sha256 are in manifest.json) and unzip it into the
project root — you get
res://addons/instaplay/(with the add-on README and CHANGELOG inside). Installation from a git repository will come after it is published. - Project → Project Settings → Plugins → enable “InstaPlay SDK” — an
InstaPlayautoload appears. - Project → Export → Web:
- Custom HTML Shell —
res://addons/instaplay/instaplay_shell.html; - Thread Support — off:
SharedArrayBufferneeds COOP/COEP headers, and the games domain does not send them (the game is embedded in the portal iframe without isolation); - Progressive Web App — off: Service Workers are forbidden on the games domain (the script gets
403, game network); renderer — Compatibility (WebGL 2).
- Custom HTML Shell —
- Export to a folder (
index.html,.wasm,.pck) and check it:instaplay test ./export(CLI).
Code
var best := 0
func _ready() -> void:
InstaPlay.paused.connect(func(_reason): get_tree().paused = true)
InstaPlay.resumed.connect(func(): get_tree().paused = false)
await InstaPlay.init()
var saved: Dictionary = await InstaPlay.saves_get("progress")
if saved.ok and saved.result != null:
best = int(saved.result.data.best)
func start_round() -> void:
InstaPlay.gameplay_start()
func finish_round(score: int) -> void:
InstaPlay.gameplay_stop()
best = max(best, score)
await InstaPlay.saves_set("progress", {"best": best})
var submitted: Dictionary = await InstaPlay.leaderboard_submit("main", score)
if not submitted.ok:
push_warning(submitted.error.code)
Requests are coroutines (await); the answer is a dictionary
{ok, result, error: {code, message, retry_after_ms}}, where result matches SDK v1. SDK errors are
data, not exceptions: check ok. The shell reports loading progress and sends ready after the engine
starts; you can call game_ready() later — the SDK ignores repeats. With auto_pause (below) you do
not need to pause the tree yourself — the sample only shows where to hook your own logic.
API
| GDScript | SDK v1 |
|---|---|
init(debug), info, locale |
init |
info.session, info.country |
session (1.1), country (1.2) in the init result |
is_paused(), is_muted() — initial values from init, then by signals |
system.pause, system.muted (1.1) |
loading_progress(p), game_ready(), gameplay_start(), gameplay_stop(), happy_moment() |
lifecycle |
level_started / level_completed / level_failed(level, props) |
level.* |
player_get(), player_get_token() |
player, the token for your own server (1.1) |
saves_get / saves_get_many / saves_set / saves_remove / saves_clear / saves_flush, set_conflict_handler(callable) |
saves |
leaderboard_submit(board, value), leaderboard_get(board, options) |
leaderboards |
analytics_event(name, props), analytics_flush() |
analytics |
ads_interstitial(placement, moment), ads_rewarded(placement), ads_available(type) |
ads (1.3) |
is_supported(feature), get_server_time() |
isSupported, getServerTime |
signals paused(reason), resumed, muted, unmuted, visibility_changed(visible), locale_changed(locale), player_changing(reason) |
portal events, playerChanging (1.1) |
auto_pause (true by default): a portal pause pauses the scene tree, mute silences the Master bus —
also right after init if the game started under a portal window or with sound off (there are no
paused/muted signals then). With auto_pause = false read the initial state with is_paused() and
is_muted(). Outside Web or without the shell a stub runs — local mode, saves and leaderboards in
memory, player_get_token() is not_supported.
Your own game server. await InstaPlay.player_get_token() → result — a portal-signed player
token (JWT ES256, 10 minutes, the SDK caches it): exchange it for your server's session
(player token). The player_changing(reason) signal (login, logout, switch) — in
~1.5 s the portal restarts the game with another player: send your data to your server.
Sign-in from the game (SDK 1.4, add-on 1.3.0). await InstaPlay.player_login() opens the portal
sign-in window over the game; result is {status, player?} (signed_in, already_signed_in,
cancelled). Show the “Save progress” button to a guest when is_supported("login") and call
player_login() right in the press handler — otherwise gesture_required. The example, the stub
(stub_login_outcome) and all errors are in the add-on README (inside the
instaplay-godot-addon-1.3.0.zip archive); rules
and patterns — Player and sign-in.
Verbose SDK log. The shell calls init before the engine starts, so init(debug) from GDScript
does not enable the log: set var IP_DEBUG = true in addons/instaplay/instaplay_shell.html.
Ads
Ads are shown by the portal; the game only asks (ads in your game):
func on_level_cleared() -> void:
InstaPlay.gameplay_stop() # interstitials only outside gameplay (otherwise reason "gameplay_active")
await InstaPlay.ads_interstitial("level_end", "next")
load_next_level()
func on_extra_life_pressed() -> void: # rewarded — only on the player's button press
var r: Dictionary = await InstaPlay.ads_rewarded("extra_life")
if r.ok and r.result.rewarded:
give_extra_life() # your server verifies r.result.grant.token
result is as in the SDK: {shown, reason}, {rewarded, reason, grant}, {available, reason, retryAfterMs}. Normal outcomes (no ad, a cooldown, the player declining) are ok = true with false
and a reason; ok = false — protocol errors only. During an ad — the paused("ad") and muted signals
(auto_pause pauses the tree and mutes Master). result.grant.token is the signed reward for your
server (reward verification); grant = null — unsigned (preview, stub).
The stub outside the portal: the outcome is InstaPlay.stub_ad_outcome (completed, no_fill,
dismissed, declined, disabled; completed by default in the editor, disabled in an export
without the shell), the length is stub_ad_seconds. “Shown” sends paused("ad") and muted, then
resumed and unmuted; an interstitial between gameplay_start() and gameplay_stop() gets
gameplay_active.
Upload
Zip the export folder contents (index.html at the zip root) and upload it in the dashboard or with
instaplay publish (Uploading a build).