Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Unity

Integrate OnsideKit into a Unity game targeting iOS with the OnsideKit Unity package — a C# wrapper over the native SDK.

The OnsideKit Unity package lets you use OnsideKit from C# in a Unity game that ships to iOS. It is a thin wrapper over the native OnsideKit iOS SDK: your C# calls are forwarded to the native SDK, and native events are delivered back to C#. The same concepts apply — products, the payment queue, transactions, login, attribution, and event tracking — so the Core Concepts and Error Reference pages are good companion reading.

  • Package: io.onside.onsidekit-unity

  • Namespace: OnsideKit

  • Requires: an iOS build target. The package is built and tested with Unity 6000.3

The native bridge exists only in an iOS device/simulator build. In the Unity Editor (and on non-iOS platforms) the API calls are no-ops, so you test the actual purchase flow by building and running on iOS.

1. Install the package

Download OnsideKit-Unity-<version>.unitypackage from the Releases of the OnsideKit-iOS repository. In Unity, choose Assets → Import Package → Custom Package, select the file, and click Import All.

The External Dependency Manager (EDM4U) is bundled in the package, and the native OnsideKit SDK is pulled in automatically when you build for iOS — you don't need to add any scoped registries or extra dependencies. The package ships Assets/OnsideKit/Editor/OnsideKitDependencies.xml, which tells EDM4U to add the native SDK as a Swift Package (https://github.com/onside-io/OnsideKit-iOS.git) pinned to the same version as the Unity package. CocoaPods is not used.

2. Create the settings asset

In Unity: Assets → Create → OnsideKit → Settings.

Create it as Assets/OnsideKit/Resources/OnsideKitSettings.asset (create the Resources folder if needed) — the iOS build step reads the settings only from that path. Set:

  • Callback Scheme (required) — your app's unique URL scheme (e.g. myapp-onside). It must match the scheme you pass to Onside.Initialize(...), and the iOS build fails if it's empty. The Onside Store app uses it to return to your game after login/payment.

  • StoreKit Configuration Path (optional) — path to a .storekit file for offline local testing. The file is copied into the generated Xcode project.

3. Write your integration

Key rules

4. Build for iOS

  1. File → Build Settings → iOS → Switch Platform, then Build.

  2. A post-process build step runs automatically and configures the generated Xcode project: it embeds OnsideKit.framework, adds onside to LSApplicationQueriesSchemes, registers your callback scheme under CFBundleURLTypes, copies your .storekit file (if set), and applies the required Swift/build settings.

  3. Open the generated .xcodeproj and run on a device (or the simulator).

You don't need to edit the Xcode project or Info.plist by hand, and you don't implement any URL handling yourself — incoming URLs are caught automatically by the bundled app controller.

How it works

Your C# calls are marshaled to the native SDK; native events are delivered back to a persistent OnsideKit GameObject (created by Initialize) via UnitySendMessage and surfaced as C# events/observer callbacks.


API Reference

Onside (static)

Initializes the SDK and creates the persistent OnsideKit GameObject. Call once at startup, before any other call. Idempotent — a second call is ignored. storeKitConfigurationName enables offline local testing.

Member
Description

OnsidePaymentQueue DefaultPaymentQueue { get; }

The shared payment queue.

void RequestLogin(Action onSuccess = null, Action<OnsideLoginError> onFailed = null)

Present the login flow. Login is also triggered on demand by a purchase or by presenting the payment methods manager.

void Logout()

End the current session.

void SetThemeMode(OnsideUIThemeMode mode)

Global theme: Auto, Light, or Dark.

void SetDelegateOptions(string countryCodeHint, OnsideLoginMethod loginMethod)

Pre-login region hint and login method (Auto by default, or Local for the in-SDK login screen). See The Onside Delegate. The older SetDelegateOptions(string countryCodeHint = null, bool forceLocalLoginMethods = false) overload is obsolete.

void SetLoginMethod(OnsideLoginMethod loginMethod)

Set the login method without changing the region hint. Throws ArgumentOutOfRangeException for an undefined value.

void SetWindowLevelOverride(double? level)

Override the window level of the SDK UI window. Pass null (the default) to let the SDK place its window above the topmost host window automatically. See Window level.

void SetApplePayMerchantIdentifier(string merchantIdentifier)

Configure Apple Pay. No-op if the SDK build has no Apple Pay. See Apple Pay.

void PresentPaymentMethodsManager(Action onSuccess = null, Action<OnsidePaymentMethodsManagerError> onFailed = null)

Show the saved-cards manager.

void GetAttributionMetadata(Action<OnsideAttributionMetadata> onSuccess = null, Action<OnsideAttributionMetadataError> onFailed = null)

Fetch attribution metadata.

void Track(string eventName, Dictionary<string, object> parameters = null)

Send an analytics event. See Event tracking.

void ResetLocalTestingState()

Reset local-testing purchase history.

Signed in-app purchase history — subscribe to the static events, then request:

See Signed In-App Purchase History.

External login — supply your app's account identifier so the SDK can create a session without the regular Onside login (see External Login):

Setting a handler enables external login; setting it to null disables it and restores the selected login method. The handler is called on Unity's main thread for each login attempt (the result is not cached) and returns your host account's external_user_id. A null result, a null task, or a failed/cancelled task falls back to the current login method.

Installation id — for support/diagnostics (see Debugging):

OnsidePaymentQueue

Accessed via Onside.DefaultPaymentQueue.

The ShouldContinueHandler is the Unity equivalent of the native storefront safety gate — see Handling Storefront & Price Changes.

IOnsidePaymentTransactionObserver

Method
When

OnsidePaymentQueueUpdatedTransactions(queue, transactions)

Transactions added or changed state. Finish each completed one.

OnsidePaymentQueueRemovedTransactions(queue, transactions)

Transactions removed (after finishing).

OnsidePaymentQueueRestoreCompletedTransactionsFinished(queue)

A restore finished successfully.

OnsidePaymentQueueRestoreCompletedTransactionsFailed(queue, error)

A restore failed.

OnsidePaymentQueueDidChangeStorefront(queue)

The storefront changed (login/logout/region).

Types

The subscription fields on OnsideProduct (the billing period and group) carry the same meaning as in the native SDK — see Subscriptions.

Errors

All error enums include an Unknown fallback. Notable cases:

Enum
Cases

OnsideProductsRequestError

Cancelled, ConnectionError, AppNotRegistered, InvalidProductIdentifier, ServiceUnavailable, InternalError

OnsidePaymentQueueAddProductError

LoginDiscarded, RejectedAfterLogin, ProductNotLoaded, NotSupportedForExternalLogin, ApplePayRequired, InternalError

OnsideTransactionsRestoreError

Cancelled, ConnectionError, AppNotRegistered, ServiceUnavailable, InternalError, LoginDiscarded

OnsidePaymentTransactionError

Cancelled, PresentationFailed, InternalError

OnsideLoginError

LoginDiscarded, RequestAlreadyInProgress

OnsidePaymentMethodsManagerError

LoginDiscarded, NotSupportedInLocalTesting, PresentationFailed, RequestAlreadyInProgress, NotSupportedForExternalLogin

OnsideAttributionMetadataError

ConnectionError, AppNotRegistered, ServiceUnavailable, InternalError, RequestAlreadyInProgress

OnsideSignedInAppsHistoryRequestError

NotLoggedIn, NotSupportedInLocalTesting, Cancelled, ConnectionError, AppNotRegistered, ServiceUnavailable, InternalError

The meaning of each case matches the native SDK — see the Error Reference. The RequestAlreadyInProgress cases are Unity-specific: they're returned when you start a one-shot request (login, payment methods, attribution) while a previous one is still pending. ProductNotLoaded is also Unity-specific: the bridge reports it when the product wasn't loaded by a prior RequestProducts (or the cache was dropped on a storefront change).

Common issues

Issue
Fix

Callback scheme doesn't work

Ensure the Callback Scheme in OnsideKitSettings matches the string passed to Onside.Initialize().

Products request returns nothing

Check that your product identifiers match what's configured in the Onside Developer Console.

Nothing happens in the Editor

Expected — the native bridge only runs in an iOS build. Test on a device/simulator.

Last updated

Was this helpful?