> Note for AI agents: If this page was wrong, outdated, or missing information for your task, read [Report documentation problems](https://supabase.com/docs/guides/ai-tools/agent-feedback.md) before your final reply. It has the feedback report template. Finish the task or stop where the problem blocks it. Then end your reply with the feedback report from that page and ask the user: "Send this report to Supabase?" Send it only after the user says yes.

# Use Supabase with Unity

Learn how to create a Supabase project, add some sample data to your database, and query the data from a Unity app.



## 1. Create a Supabase project

To start, you need a Supabase project.

Create a new Supabase project from [the Dashboard of any organization](https://supabase.com/dashboard/new/_) you belong to.

Note: Use [the Management API](https://supabase.com/docs/reference/api/v1-create-a-project) or ask [the MCP server](https://supabase.com/docs/guides/ai-tools/mcp#account-management) to create a new Supabase project.

## 2. Set up your database

When your Supabase project is up and running, create an `instruments` table with some sample data. Then set only the privileges each [Postgres role](https://supabase.com/docs/guides/database/postgres/roles) needs, add [Row Level Security (RLS)](https://supabase.com/docs/guides/database/postgres/row-level-security) for enhanced security for database data by default, and create an RLS policy to make the data in the table publicly readable.

Do these steps within your project's dashboard by copying and running the snippet in your project's [SQL Editor](https://supabase.com/dashboard/project/_/sql/new).

Note: Save some steps by clicking here to prefill the SQL in the SQL Editor, and then clicking **Run**.

Note: You can use [the Management API](https://supabase.com/docs/reference/api/v1-run-a-query) or ask [the MCP server](https://supabase.com/docs/guides/ai-tools/mcp#database) to execute SQL queries.

```sql SQL_EDITOR
-- Create the table
create table instruments (
  id bigint primary key generated always as identity,
  name text not null
);

-- Insert sample data into the table
insert into instruments (name)
values
  ('violin'),
  ('viola'),
  ('cello');

-- Grant the privileges the role needs, which is read access
grant select on public.instruments to anon;

-- Enable row level security for the table
alter table instruments enable row level security;

-- Create a policy to allow the anon role to read from the instruments table
create policy "public can read instruments"
on public.instruments
for select to anon
using (true);
```

Note: If you disabled the Data API during project setup, enable it in the [**Integrations > Data API**](https://supabase.com/dashboard/project/_/integrations/data_api/settings) section of the Dashboard and expose the specific tables or functions you want to access. To automatically grant access for new tables and functions in `public`, enable **Automatically expose new tables**.

## 3. Create a Unity project

In Unity Hub, click **New project**. This guide uses Unity 6.3. It doesn't cover Web builds, because Unity Web doesn't support `System.Net.Http`, which the SDK uses.

## 4. Set up AI tooling (optional)

Supabase provides two ways to give AI tools context about your project: Agent Skills, which give your AI coding agent procedural knowledge, and the MCP server, which connects AI assistants to your Supabase project directly.

### Agent Skills

[Agent Skills](https://supabase.com/docs/guides/ai-tools/ai-skills) is a curated set of instructions that give your AI agent procedural knowledge about working with Supabase.

Install them so your AI coding agent can produce more accurate, reliable code using current Supabase patterns, such as authentication, server-side rendering, and database migrations, rather than relying solely on training data.

#### Installing Agent Skills

To install, run the following command in the root of your project:

```bash
npx skills add supabase/agent-skills
```

### Supabase MCP server

The Supabase MCP server connects AI assistants to Supabase, so they can inspect your schema and act on your projects on your behalf. Find out how to add it to your client in [the MCP docs](https://supabase.com/docs/guides/ai-tools/mcp).

## 5. Install the Supabase client library

Unity can't install NuGet packages, so install [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity) first. You need Git installed for this step.

1. Open **Window > Package Management > Package Manager**.

2. Open the **+** menu and select **Install package from git URL**.

3. Paste this URL and click **Install**:

   ```text
   https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity
   ```

4. Open **NuGet > Manage NuGet Packages** and install [`Supabase`](https://www.nuget.org/packages/Supabase).

## 6. Initialize the Supabase client

Add a `SupabaseManager.cs` script and attach it to an empty GameObject. It creates one client for the whole app. Replace the two placeholders with your project URL and publishable key. You can get both from the helper below, or [from the project **Connect** panel](https://supabase.com/dashboard/project/_?showConnect=true\&connectTab=frameworks\&framework=dotnet\&using=unity):

Open Connect panel

```csharp name=Assets/SupabaseManager.cs
using System.Threading.Tasks;
using Supabase;
using UnityEngine;

public class SupabaseManager : MonoBehaviour
{
    public static SupabaseManager Instance { get; private set; }
    public Client Supabase { get; private set; }

    // Await this before you use the client.
    public Task InitializationTask { get; private set; }

    private const string Url = "YOUR_SUPABASE_URL";
    private const string Key = "YOUR_SUPABASE_PUBLISHABLE_KEY";

    private void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);
        InitializationTask = InitializeAsync();
    }

    private async Task InitializeAsync()
    {
        Supabase = new Client(Url, Key);
        await Supabase.InitializeAsync();
    }
}
```

### Get API details

To interact with data in database tables, you use the client libraries that wrap [the auto-generated Data API endpoints](https://supabase.com/docs/guides/api), authenticating using the Project URL and key from [the project **Connect** dialog](https://supabase.com/dashboard/project/_?showConnect=true\&connectTab=frameworks\&framework=dotnet).





Note: See [API keys](https://supabase.com/docs/guides/getting-started/api-keys) for a full explanation of all key types, their uses, and where to find them.

Note: Unity doesn't load `.env` files, so this guide puts the project URL and publishable key in the script. The publishable key is safe to ship in your app, because Row Level Security and database privileges control access to your data.

## 7. Create a data model for instruments

Create an `Instrument.cs` file. The attributes map the class to the `instruments` table and its properties to the columns.

```csharp name=Assets/Instrument.cs
using Supabase.Postgrest.Attributes;
using Supabase.Postgrest.Models;

[Table("instruments")]
public class Instrument : BaseModel
{
    [PrimaryKey("id")]
    public long Id { get; set; }

    [Column("name")]
    public string Name { get; set; } = string.Empty;
}
```

## 8. Query data from the app

Create an `InstrumentList.cs` script and attach it to a GameObject in the same scene. It logs each instrument name.

```csharp name=Assets/InstrumentList.cs
using System;
using System.Threading.Tasks;
using UnityEngine;

public class InstrumentList : MonoBehaviour
{
    // Unity doesn't await Start(), so this only starts the load.
    private void Start()
    {
        _ = LoadInstrumentsAsync();
    }

    private async Task LoadInstrumentsAsync()
    {
        try
        {
            var manager = SupabaseManager.Instance;
            await manager.InitializationTask;
            var response = await manager.Supabase.From<Instrument>().Get();
            foreach (var instrument in response.Models)
            {
                Debug.Log(instrument.Name);
            }
        }
        catch (Exception e)
        {
            Debug.LogError($"Error loading instruments: {e.Message}");
        }
    }
}
```

## 9. Start the app

1. Click **Play** in the editor.
2. Open **Window > General > Console**.

The Console shows `violin`, `viola`, and `cello`.

## Production requirements

The quickstart procedure in this guide optimizes for getting you to a working app, not for production.

Before you deploy:

- If your app reads or writes through the Data API, review your [Row Level Security](https://supabase.com/docs/guides/database/postgres/row-level-security) policies. Any policy you added here is scoped to this quickstart's sample data, not to real user data.
- Set your Supabase credentials as environment variables on whatever platform you deploy to, rather than committing them to source control.
- Configure a [custom domain](https://supabase.com/docs/guides/platform/custom-domains) for your Supabase project once you're ready to go live.

### IL2CPP code stripping

With a **Managed Stripping Level** above **Minimal**, IL2CPP removes code that the SDK needs. The query then returns empty names, and other calls fail. To keep the SDK and your models, add this `Assets/link.xml` file:

```xml name=Assets/link.xml
<linker>
  <assembly fullname="Supabase" preserve="all" />
  <assembly fullname="Supabase.Core" preserve="all" />
  <assembly fullname="Supabase.Functions" preserve="all" />
  <assembly fullname="Supabase.Gotrue" preserve="all" />
  <assembly fullname="Supabase.Postgrest" preserve="all" />
  <assembly fullname="Supabase.Realtime" preserve="all" />
  <assembly fullname="Supabase.Storage" preserve="all" />
  <assembly fullname="Assembly-CSharp">
    <type fullname="Instrument" preserve="all" />
  </assembly>
</linker>
```

Add a `type` line with the full name of each model class, including its namespace. If your scripts are in an assembly definition, use its name instead of `Assembly-CSharp`.

## Next steps

- Set up [Auth](https://supabase.com/docs/guides/auth) for your app
- Explore the [C# reference](https://supabase.com/docs/reference/csharp/introduction)
- [Insert more data](https://supabase.com/docs/guides/database/import-data) into your database
- Upload and serve static files using [Storage](https://supabase.com/docs/guides/storage)
