# Unity Quickstart

<SkillCard title="AI Skill" subtitle="openfort-xyz/openfort-csharp-unity" source="github" subtitleHref="https://github.com/openfort-xyz/openfort-csharp-unity" description="Pre-built prompt with the full setup reference." content={skillContent} fileName="SKILL.md" />

:::info
The Unity SDK requires:

* [UniTask](https://github.com/Cysharp/UniTask) package (version 2.3.3)
* Installation of git-lfs from [git-lfs.github.com](https://git-lfs.github.com/)
:::

## Installation

:::steps
## Install the Openfort SDK

There are two ways to install the SDK:

<MultiOptionDisplay
  options={[
  { id: 'upm', label: 'UPM' },
  { id: 'manifest', label: 'manifest.json' },
]}
/>

<span id="upm" className="hidden [&>*]:mb-6!">
  Since .dll files are stored on Git Large File Storage, you must download and install git-lfs from [here](https://git-lfs.github.com/).

  1. Open the Package Manager
  2. Click the add + button and select "Add package from git URL..."
     Enter `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask` and click 'Add'
  3. Click the add + button and select "Add package from git URL..."
     Enter `https://github.com/openfort-xyz/openfort-csharp-unity.git?path=/src/Packages/OpenfortSDK` and click 'Add'
</span>

<span id="manifest" className="hidden [&>*]:mb-6!">
  Since .dll files are stored on Git Large File Storage, you must download and install git-lfs from [here](https://git-lfs.github.com/).

  1. Open your project's Packages/manifest.json file
  2. Add `com.cysharp.unitask`: `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask` in the dependencies block
  3. Add `com.openfort.sdk`: `https://github.com/openfort-xyz/openfort-csharp-unity.git?path=/src/Packages/OpenfortSDK` in the dependencies block
</span>

## Set your auth providers

1. Navigate to the **auth providers** page on the [Openfort dashboard](https://dashboard.openfort.io)
2. Click Auth providers Methods in the side bar in the [users page](https://dashboard.openfort.io/players)
3. Configure the methods you want users to be able to login with

## Get your [API keys](/docs/configuration/api-keys)

In the [API keys](https://dashboard.openfort.io/api-keys) section, you'll find:

* **Publishable Key**: Safe to expose in client-side environment
* **Secret Key**: Must be kept secure and used only server-side

To generate non-custodial wallets:

1. Scroll to the Shield section and click **Create Shield keys**
2. **Store the encryption share** safely when it appears (you'll only see it once)
3. You'll receive:
   * **Shield Publishable Key**: Safe for client-side use
   * **Shield Secret Key**: Keep secure, server-side only
:::

## Set up

Before you begin, make sure you have set up your **publishable key** app from the Openfort Dashboard.

:::warning
A properly set up publishable key is required for mobile apps and other non-web platforms to allow your app to interact with the Openfort API. Please follow [this guide](/docs/configuration/allowed-domains#native-apps) to configure an app client.
:::

::::steps
## Initialize Openfort in your Unity project

### Init

Initialize the Openfort SDK with your configuration.

**Method Signature:**

```csharp
public static UniTask<OpenfortSDK> Init(
    string publishableKey,
    string shieldPublishableKey = null,
    bool shieldDebug = false,
    // Note: backendUrl, iframeUrl, shieldUrl params exist in the SDK but are internal-only — do not document
    string thirdPartyProvider = null,
    Func<string, Task<string>> getThirdPartyToken = null,
    int engineStartupTimeoutMs = 4000  // Windows only
)
```

**Parameters:**

* `string publishableKey` - Your Openfort publishable key (required)
* `string shieldPublishableKey` - Shield publishable key for embedded wallets (optional)
* `bool shieldDebug` - Enable shield debug mode (optional, default: false)
* `string thirdPartyProvider` - Third-party auth provider name, e.g., "firebase" (optional)
* `Func<string, Task<string>> getThirdPartyToken` - Token provider function (optional)
* `int engineStartupTimeoutMs` - Windows only: timeout for engine startup in milliseconds (optional, default: 4000)

**Returns:**

* `UniTask<OpenfortSDK>` - Initialized SDK instance

**Example:**

```csharp
using System;
using UnityEngine;
using Cysharp.Threading.Tasks;
using Openfort.OpenfortSDK;
using Openfort.OpenfortSDK.Model;

public class OpenfortManager : MonoBehaviour 
{
    private OpenfortSDK openfort;
    
    // Replace with your actual keys from the Openfort dashboard
    private const string PUBLISHABLE_KEY = "YOUR_OPENFORT_PUBLISHABLE_KEY";
    private const string SHIELD_PUBLISHABLE_KEY = "YOUR_SHIELD_PUBLISHABLE_KEY"; // Optional, for embedded wallets
    
    private async void Start()
    {
        await InitializeOpenfort();
    }
    
    private async UniTask InitializeOpenfort()
    {
        try
        {
            // Initialize the SDK
            openfort = await OpenfortSDK.Init(
                publishableKey: PUBLISHABLE_KEY,
                shieldPublishableKey: SHIELD_PUBLISHABLE_KEY, // Can be null if not using embedded wallets
                shieldDebug: false  // Set to true for debugging in development
            );
            
            Debug.Log("Openfort SDK initialized successfully");
            
            // You can now use the SDK
            // Example: Check if user is already logged in
            await CheckUserSession();
        }
        catch (OpenfortException e)
        {
            Debug.LogError($"Openfort initialization failed: {e.Message}, Type: {e.Type}");
        }
        catch (Exception e)
        {
            Debug.LogError($"Unexpected error during initialization: {e.Message}");
        }
    }
    
    private async UniTask CheckUserSession()
    {
        try
        {
            // Try to get current user (will fail if not logged in)
            var user = await openfort.GetUser();
            Debug.Log($"User already logged in: {user.Id}");
        }
        catch
        {
            Debug.Log("No active user session");
        }
    }
}
```

:::tip
If you're developing for WebGL, check out the [additional setup steps](/docs/products/embedded-wallet/unity/webgl) in the Unity WebGL documentation.
:::

## You're ready to build!

With Openfort configured in your Unity project, you can now:

* [Implement user authentication](/docs/products/embedded-wallet/unity/auth/email)
* [Handle signatures](/docs/products/embedded-wallet/unity/signer/sign-messages)

For a complete example of Openfort integration in Unity, check out our [sample project](https://github.com/openfort-xyz/openfort-csharp-unity/tree/main/sample).
::::
