Generated from the SDK’s canonical reference at v0.3.6. Fixes belong in pio-unity-sdk, not here.
Conventions
PIO (static class)
The sole public entry point. Studios interact with the SDK exclusively through
this class.
Properties
All properties are read-only and safe to read at any time.
Events
event Action<PioError> OnError
Raised when the SDK encounters an error: auth, a decision fallback, event
ingestion, an evicted queue, or an unhandled exception inside SDK code. Always
fires on the Unity main thread, so handlers may touch Unity APIs. Standard C#
event: subscribe with +=, unsubscribe with -=. Subscribe before Init
to catch init-time errors. See error-handling.md.
Methods
Init(PioConfig config, PioOptions options = null) → Task
Initialise the SDK. Resolves the stable user ID, authenticates with the
inference Worker (when tracking is enabled), warms the connection, and starts the
session.
Init() → Task
Zero-argument overload that loads a PioSettings
asset from Resources/PioSettings.asset, so no code configuration is required.
Throws InvalidOperationException if no asset is present. For explicit config or
secure runtime key injection, use the two-argument overload (its arguments take
precedence over the asset).
SetTrackingEnabled(bool enabled) → Task
Toggle data collection at runtime (e.g. after a CMP consent change).
See cmp-integration.md.
GetDecision(string actionDefKey, CancellationToken ct = default) → Task<DecisionResult>
Request a decision for a registered action definition.
TrackEvent(string eventType[, double value]) → void
Fire a custom game event, optionally with a non-negative numeric value.
Enqueues synchronously and returns immediately.
The numeric overload writes
value to the top-level event_value field.
SetState(string key, object value) → void
Set a custom game state value included in the next GetDecision snapshot.
Keys should match state definitions registered in pio-web (e.g.
std_level_index).
PioConfig (sealed class)
Connection configuration passed to PIO.Init. The three string identifiers are
required and validated at init time. Use object-initializer syntax.
ActionDef (sealed class)
A single action space registered in PioConfig.Actions.
PioOptions (sealed class)
Behavioural options, separate from connection config. Optional second argument to
PIO.Init.
PioSettings (ScriptableObject)
Inspector-editable configuration asset at Assets/Resources/PioSettings.asset,
loaded by the zero-argument PIO.Init(). The Setup Wizard generates it.
Carries the PioConfig connection fields and the PioOptions knobs, plus
AutoInitialize (auto-init on game start, off by default). PioConfig.Actions
stays code-only: Unity can’t serialise a dictionary in the Inspector.
Ship exactly one PioSettings asset: Resources.Load returns the first one
found in any Resources/ folder, so a duplicate silently shadows the real one.
DecisionResult (sealed class)
Immutable result from PIO.GetDecision. Studios cannot construct instances; they
branch on Source.
Option payload
An action option can carry a payload (difficulty curves, popup copy, discount percentages) edited in the dashboard and delivered with the decision. The model still chooses among the same option keys; the payload is opaque to training. So a studio retunes numbers server-side with no client release and no retraining. Prefer the generated typed payload classes (PIO > Generate Code Constants),
which give you compile-time names and types. The getters below are the low-level
escape hatch they are built on, and the right tool for a json parameter.
Generated payload classes
Codegen writes one{Action}Payload class per action that declares parameters,
into Assets/PIO.Generated/PioPayloads.cs, with the schema’s defaults compiled
in:
From(null) is safe: every property then returns its compiled-in default, which
is what you get when tracking is disabled.
Enum choices are emitted as
const strings rather than a C# enum: a value added
in the dashboard later would have no enum member to map onto, and inventing one at
runtime needs reflection, which is not AOT-safe.
Generated code lands in Assembly-CSharp. If your game code lives in its own
assembly definition, add a reference to the assembly containing Assets/PIO.Generated
(or move the folder inside your asmdef) before using these classes.
Schema drift
The Editor compares the server’s schema againstPioGeneratedSchema.json on focus
and on entering play mode, and warns when a parameter is added, removed, or
re-typed, the changes that stale your generated code. Editing a parameter’s
default or description is not drift: defaults are re-read from the server on
every decision. Regenerate to clear the warning.
PioError (sealed class)
An error surfaced via PIO.OnError. Studios receive instances; they never
construct them. Compare Code against PioErrorCodes.
PioErrorCodes (static class)
Stable string codes for PioError.Code. The set is fixed for the cloud-only
architecture.
Enums
PioState
Transitions:
Uninitialized → Initializing → Ready, or Initializing → Failed.
DecisionSource
PioErrorSeverity
PioEnvironment
Studios only target
Production. Internal/test rigs use the *UrlOverride
fields on PioConfig.
Stability
Pre-1.0 (current): minor version bumps may include source-breaking changes to the public API. Binary compatibility is not guaranteed. Pin to exact versions. Post-1.0 (future): semver applies: patch = bug fix, minor = additive only, major = breaking. The symbols above become the compatibility baseline.Assembly visibility
internal members of PIO.Runtime are visible only to PIO.Tests.Runtime and
PIO.Tests.Editor, enforced in Runtime/Properties/AssemblyInfo.cs. No other
assembly has access.