---
title: "Unity"
description: "Learn how to set up Sentry in your Unity project and capture your first events."
url: https://docs.sentry.io/platforms/unity/
---

# Sentry for Unity

Our Unity SDK builds on top of the [.NET SDK](https://docs.sentry.io/platforms/dotnet.md) and extends it with Unity-specific features. It gives you helpful hints for where and why an error or performance issue might have occurred.

SDK Features

* [Automatically captures C# errors](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md) on multiple platforms, including: Android, iOS, macOS, Linux, Windows, and WebGL

* Line numbers for C# [exceptions in IL2CPP builds](https://docs.sentry.io/platforms/unity/configuration/il2cpp.md)

* [Native support](https://docs.sentry.io/platforms/unity/native-support.md) for automatic crash error tracking for:

  * Android by using the [Android SDK](https://docs.sentry.io/platforms/android.md) to support Java, Kotlin, C and C++
  * iOS by using the [iOS SDK](https://docs.sentry.io/platforms/apple/guides/ios.md) to support Objective-C, Swift, C and C++
  * Windows and Linux by using the [Native SDK](https://docs.sentry.io/platforms/native.md) to support C and C++ with minidumps
  * macOS by using the [macOS SDK](https://docs.sentry.io/platforms/apple/guides/macos.md) to support Objective-C, Swift, C and C++
  * [PlayStation](https://docs.sentry.io/platforms/playstation.md), [Xbox](https://docs.sentry.io/platforms/xbox.md) and [Nintendo Switch](https://docs.sentry.io/platforms/nintendo-switch.md) support

* [Screenshot attachments](https://docs.sentry.io/platforms/unity/enriching-events/screenshots.md) for errors

* [ViewHierarchy attachments](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md) for errors

* [Offline Caching](https://docs.sentry.io/platforms/unity/configuration/options.md#InitCacheFlushTimeout) stores event data to disk in case the device is not online

* [Release Health](https://docs.sentry.io/platforms/unity/configuration/releases.md) to keep track of crash-free users and sessions

* [Structured Logging](https://docs.sentry.io/platforms/unity/logs.md) to capture and send log messages with additional context

* [Metrics](https://docs.sentry.io/platforms/unity/metrics.md) to track counters, gauges, and distributions

* [Automatically adding breadcrumbs](https://docs.sentry.io/platforms/unity/enriching-events/breadcrumbs.md#automatic-breadcrumbs) for

  * Unity's `Debug.Log` and `Debug.LogWarning`
  * Scene load, unload, active change

* [Event debouncing](https://docs.sentry.io/platforms/unity/configuration/event-debouncing.md) to handle high amounts of log output i.e. during `Update`

## [Prerequisites](https://docs.sentry.io/platforms/unity.md#prerequisites)

You need:

* A Sentry [account](https://sentry.io/signup/) and [project](https://docs.sentry.io/product/projects.md)

## [Install](https://docs.sentry.io/platforms/unity.md#install)

Install the package via the [Unity Package Manager using a Git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html) to Sentry's SDK repository:

```bash
https://github.com/getsentry/unity.git
```

To use a specific version of the SDK, append it to the URL (for example, `#4.13.0`).

## [Configure](https://docs.sentry.io/platforms/unity.md#configure)

**Error Monitoring**, including native crashes on supported platforms, starts working as soon as the SDK has your DSN. **Application Metrics** are enabled by default and you'll learn how to send them in [Send Application Metrics](https://docs.sentry.io/platforms/unity.md#send-application-metrics-). This guide also enables **Tracing**, **Logs**, and **User Feedback**.

### [Add Your DSN](https://docs.sentry.io/platforms/unity.md#add-your-dsn)

Installing the SDK adds an entry to Unity's top menu: **Tools > Sentry**. When you first open the menu, a wizard guides you through associating your game with a Sentry project and sets up the initial configuration for you.

The minimum configuration required is the [DSN](https://docs.sentry.io/concepts/key-terms/dsn-explainer.md) to your project.

```json
{
  "public-dsn": "https://<key>@o<orgId>.ingest.sentry.io/<projectId>"
}
```

Sentry saves your configuration to `Assets/Resources/Sentry/SentryOptions.asset` and reads from there both at build time and runtime.

### [Configure the SDK Programmatically](https://docs.sentry.io/platforms/unity.md#configure-the-sdk-programmatically)

You can set most options in the Sentry configuration window. To set them in code, open **Tools > Sentry**, go to the **Options Config** tab, and click **New** to create an options configuration script. The SDK calls its `Configure` method on each startup, after it reads the configuration window settings, so values you set here take precedence.

The snippet also turns on:

* Tracing: via [`TracesSampleRate`](https://docs.sentry.io/platforms/unity/configuration/options.md#TracesSampleRate). The SDK automatically creates [transactions for startup and scene loading](https://docs.sentry.io/platforms/unity/tracing/instrumentation/automatic-instrumentation.md).
* Logs: via [`EnableLogs`](https://docs.sentry.io/platforms/unity/logs.md). You can also check **Enable Structured Logging** in **Tools > Sentry > Logging**.
* Screenshots: via [`AttachScreenshot`](https://docs.sentry.io/platforms/unity/configuration/options.md#AttachScreenshot), which attaches a [screenshot](https://docs.sentry.io/platforms/unity/enriching-events/screenshots.md) of your game to errors.
* View Hierarchy: via [`AttachViewHierarchy`](https://docs.sentry.io/platforms/unity/configuration/options.md#AttachViewHierarchy), which attaches the active scene's [view hierarchy](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md) to errors.

Don't need a feature? Remove its options from the snippet.

```csharp
using Sentry.Unity;

public class SentryOptionConfiguration : SentryOptionsConfiguration
{
    public override void Configure(SentryUnityOptions options)
    {
        // Enables Tracing.
        // Set to 1.0 to capture 100% of transactions for tracing.
        // We recommend reducing this value in production.
        options.TracesSampleRate = 1.0;

        // Enables Logs. Requires Unity SDK 4.0.0 or later.
        options.EnableLogs = true;

        // Attaches a screenshot and the active scene's view hierarchy to errors.
        options.AttachScreenshot = true;
        options.AttachViewHierarchy = true;
    }
}
```

See [Programmatic Configuration](https://docs.sentry.io/platforms/unity/configuration/options/programmatic-configuration.md) for how these options apply to the native SDKs, and [Options](https://docs.sentry.io/platforms/unity/configuration/options.md) for all available options.

### [Collect User Feedback](https://docs.sentry.io/platforms/unity.md#collect-user-feedback)

To let players report problems from inside your game, drag the **User Feedback** prefab from the Sentry SDK package into any scene. The prefab adds a feedback button and form and works without additional configuration. It's available in Unity SDK 4.0.0 and later.

See [Set Up User Feedback](https://docs.sentry.io/platforms/unity/user-feedback.md) to customize the form or send feedback with your own UI.

### [Upload Debug Symbols](https://docs.sentry.io/platforms/unity.md#upload-debug-symbols)

Sentry needs [debug information files](https://docs.sentry.io/platforms/unity/data-management/debug-files.md) to symbolicate native crashes and to show C# line numbers for [exceptions in IL2CPP builds](https://docs.sentry.io/platforms/unity/configuration/il2cpp.md). The SDK uploads these files automatically when you build your game in the editor, but you need to configure the upload first.

Open **Tools > Sentry**, go to the **Debug Symbols** tab, and enter your [Auth Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/), organization slug, and project name. The SDK stores these settings in `Assets/Plugins/Sentry/SentryCliOptions.asset`, which should **not** be made publicly available.

IL2CPP line number support is enabled by default and relies on this upload.

### [Include the Crash Handler on Windows](https://docs.sentry.io/platforms/unity.md#include-the-crash-handler-on-windows)

On Windows, the SDK captures native crashes with the [Native SDK](https://docs.sentry.io/platforms/native.md) and copies `crashpad_handler.exe` to your build output directory. Include this executable when you ship your game. Learn more about native crash support on each platform in [Native Support](https://docs.sentry.io/platforms/unity/native-support.md).

## [Send Logs](https://docs.sentry.io/platforms/unity.md#send-logs)

Use `SentrySdk.Logger` to send logs at different levels, such as `LogInfo`, `LogWarning`, or `LogError`. Logs require Unity SDK 4.0.0 or later and `EnableLogs`, which the snippet in [Configure](https://docs.sentry.io/platforms/unity.md#configure-the-sdk-programmatically) turns on.

With logs enabled, the SDK also forwards Unity's `Debug.LogWarning`, `Debug.LogAssertion`, `Debug.LogError`, and `Debug.LogException` calls to Sentry by default. You can change which log types it forwards with [automatic Unity log forwarding](https://docs.sentry.io/platforms/unity/logs.md#automatic-unity-log-forwarding).

See [Set Up Logs](https://docs.sentry.io/platforms/unity/logs.md) for all available logging methods and configuration options.

```csharp
SentrySdk.Logger.LogInfo("A simple debug log message");

SentrySdk.Logger.LogWarning(log =>
{
    log.SetAttribute("player_id", playerId);
    log.SetAttribute("scene", SceneManager.GetActiveScene().name);
}, "Player {0} is low on health", playerId);
```

## [Send Application Metrics NEW](https://docs.sentry.io/platforms/unity.md#send-application-metrics-)

Use `SentrySdk.Metrics` to send counters, gauges, and distributions from your game. Metrics require Unity SDK 4.2.0 or later and are enabled by default.

See [Set Up Metrics](https://docs.sentry.io/platforms/unity/metrics.md) for all available metric types and configuration options.

```csharp
SentrySdk.Metrics.EmitCounter("player_interaction", 5,
    new Dictionary<string, object> { ["scene"] = "MainMenu" });

SentrySdk.Metrics.EmitGauge("scene_load", 15.0, MeasurementUnit.Duration.Millisecond,
    new Dictionary<string, object> { ["scene"] = "Level1" });

SentrySdk.Metrics.EmitDistribution("scene_load", 15.0, MeasurementUnit.Duration.Millisecond,
    new Dictionary<string, object> { ["scene"] = "Level1" });
```

## [Verify Your Setup](https://docs.sentry.io/platforms/unity.md#verify-your-setup)

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

Add this script to a GameObject in your scene and enter Play mode. The script throws an unhandled `NullReferenceException`, which Sentry captures as an error:

```csharp
using UnityEngine;

public class TestMonoBehaviour : MonoBehaviour
{
    private GameObject testObject = null;

    void Start()
    {
        // This throws an unhandled 'NullReferenceException'
        testObject.GetComponent<Transform>();
    }
}
```

You can also import the "Unity of Bugs" sample from the Package Manager to trigger common bugs, including native errors, without writing them yourself.

### [View Captured Data in Sentry](https://docs.sentry.io/platforms/unity.md#view-captured-data-in-sentry)

Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear). Select **Issues** in the sidebar to find the new issue. Errors captured in the Unity Editor use the `editor` environment.

## [Next Steps](https://docs.sentry.io/platforms/unity.md#next-steps)

At this point, you should have integrated Sentry into your Unity game. Here's what to explore next:

* Explore [practical guides](https://docs.sentry.io/get-started/guides.md) on what to monitor, log, track, and investigate after setup
* Instrument more operations with [custom instrumentation](https://docs.sentry.io/platforms/unity/tracing/instrumentation/custom-instrumentation.md)

Are you having problems setting up the SDK or integration?

* Find various topics in [Troubleshooting](https://docs.sentry.io/platforms/unity/troubleshooting.md)
* [Get support](https://www.sentry.help/en/)

## Topics

- [Basic Configuration](https://docs.sentry.io/platforms/unity/configuration.md)
- [Game Consoles](https://docs.sentry.io/platforms/unity/game-consoles.md)
- [Usage](https://docs.sentry.io/platforms/unity/usage.md)
- [Native Support](https://docs.sentry.io/platforms/unity/native-support.md)
- [App Hangs and ANRs](https://docs.sentry.io/platforms/unity/app-hangs.md)
- [Enriching Events](https://docs.sentry.io/platforms/unity/enriching-events.md)
- [Data Management](https://docs.sentry.io/platforms/unity/data-management.md)
- [Tracing](https://docs.sentry.io/platforms/unity/tracing.md)
- [Logs](https://docs.sentry.io/platforms/unity/logs.md)
- [Application Metrics](https://docs.sentry.io/platforms/unity/metrics.md)
- [User Feedback](https://docs.sentry.io/platforms/unity/user-feedback.md)
- [Migration Guide](https://docs.sentry.io/platforms/unity/migration.md)
- [Troubleshooting](https://docs.sentry.io/platforms/unity/troubleshooting.md)

---

Find other pages: [Sitemap](https://docs.sentry.io/sitemap.md) lists every page with a one-line summary, and [llms.txt](https://docs.sentry.io/llms.txt) gives an overview with guidance for agents.
