---
title: "Native Support"
description: "Learn how the Unity SDK handles native support."
url: https://docs.sentry.io/platforms/unity/native-support/
---

# Native Support for Unity

The Unity SDK captures C# errors on every platform it supports. On most platforms, it also includes a native SDK that captures native crashes, such as crashes in the Unity engine or in native plugins. Native support is on by default.

## [Supported Platforms](https://docs.sentry.io/platforms/unity/native-support.md#supported-platforms)

| Platform                           | Native crashes | Native SDK                                                                   | Requirements            |
| ---------------------------------- | -------------- | ---------------------------------------------------------------------------- | ----------------------- |
| Android                            | Yes            | sentry-java with the NDK integration                                         | IL2CPP                  |
| iOS                                | Yes            | sentry-cocoa                                                                 |                         |
| Windows (x64, x86)                 | Yes            | sentry-native with Crashpad, or the experimental Native backend              |                         |
| macOS                              | Yes            | sentry-cocoa, or sentry-native with the experimental Native backend          | IL2CPP for sentry-cocoa |
| Linux (x86\_64, ARM64)             | Yes            | sentry-native with Breakpad, or the experimental Native backend              |                         |
| Xbox, PlayStation, Nintendo Switch | Yes            | See [Game Consoles](https://docs.sentry.io/platforms/unity/game-consoles.md) |                         |
| WebGL                              | No             |                                                                              |                         |
| visionOS, UWP                      | No             |                                                                              |                         |

On visionOS and UWP, the SDK runs on a best-effort basis, without offline caching or session tracking. The SDK supports Unity 2021.3 and later. Dedicated server builds for Windows, macOS, and Linux get the same native support as players. On consoles, the SDK supports Xbox with the GDK, PlayStation 5, Nintendo Switch, and Nintendo Switch 2. The SDK doesn't support PlayStation 4, Xbox One without the GDK, tvOS, Embedded Linux, or Cloud Rendering.

## [Scope Sync](https://docs.sentry.io/platforms/unity/native-support.md#scope-sync)

The SDK syncs the scope you set in C# to the native SDK, so native crashes include it. It syncs:

* Breadcrumbs
* Tags
* Extras
* User
* Environment
* Trace
* Attachments

Some scope data doesn't reach native crashes:

* Custom contexts you set through `scope.Contexts`. The SDK only syncs the contexts it collects itself, such as device and app data.
* Attachments on iOS, and on macOS with the default Cocoa backend.
* With [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.md), the app's own SDK owns part of the scope. On iOS, that's the user, environment, and trace. On Android, it's the trace, and the user when the game runs in the app's process.
* On Android, setting `NdkScopeSyncEnabled` to `false` turns off scope sync for NDK crashes.

## [Mobile](https://docs.sentry.io/platforms/unity/native-support.md#mobile)

The native crash support for Android and iOS is provided by adding platform-specific SDKs to the generated Xcode and Gradle projects at build time.

Android native support requires the IL2CPP scripting backend. With Mono, the SDK captures C# errors only.

On Android, `NdkIntegrationEnabled`, `NdkScopeSyncEnabled`, `AndroidTombstoneEnabled`, and `AndroidReportHistoricalTombstones` control the NDK integration and tombstone reporting. On iOS, `IosWatchdogTerminationIntegrationEnabled` controls watchdog termination reporting. Learn more in [Options](https://docs.sentry.io/platforms/unity/configuration/options.md).

### [Initialization of the Native SDKs](https://docs.sentry.io/platforms/unity/native-support.md#initialization-of-the-native-sdks)

The [iOS SDK](https://docs.sentry.io/platforms/apple/guides/ios.md) and [Android SDK](https://docs.sentry.io/platforms/android.md) are capable of self-initializing before the Unity engine itself is started. This allows us to capture bugs/crashes happening within the engine itself. There are three initialization types:

* `NativeInitializationType.Runtime`: Native SDKs initialize during runtime alongside the C# SDK
* `NativeInitializationType.BuildTime`: Native SDKs initialize before Unity engine starts
* `NativeInitializationType.External`: The app that embeds the game provides and initializes the native SDKs, when using [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.md)

Set the type with the `AndroidNativeInitializationType` and `IosNativeInitializationType` options in an [options configuration script](https://docs.sentry.io/platforms/unity/configuration/options/programmatic-configuration.md). Both default to `Runtime`.

### [Runtime Initialization (Default)](https://docs.sentry.io/platforms/unity/native-support.md#runtime-initialization-default)

With runtime initialization, the native SDKs are initialized at runtime alongside the C# SDK. This allows all options to be dynamically configured through C# code during execution.

#### [Android](https://docs.sentry.io/platforms/unity/native-support.md#android)

At build time, the SDK modifies the generated Gradle project to include the Android SDK but sets `io.sentry.auto-init` in the `AndroidManifest.xml` to `false`. The Unity SDK will then initialize the Android SDK when it initializes itself.

#### [iOS](https://docs.sentry.io/platforms/unity/native-support.md#ios)

At build time, the SDK modifies the generated Xcode project to include the iOS SDK but will not modify the `main.mm` file or write the options to file. The Unity SDK will then initialize the iOS SDK when it initializes itself.

### [Build Time Initialization](https://docs.sentry.io/platforms/unity/native-support.md#build-time-initialization)

When using build time initialization, the native SDKs are configured during build time and initialize before the Unity engine starts. This means the options are baked into the outputted projects and cannot be modified at runtime via C# code. Changes to properties like `Release` and `Environment` will not apply to events generated by the native SDKs.

#### [Android](https://docs.sentry.io/platforms/unity/native-support.md#android-1)

The SDK modifies the generated Gradle project to include the Android SDK. At build time, it will also write the options to the `AndroidManifest.xml`. These options cannot be changed at runtime. Changes to the options in the configuration callback will not affect the Android SDK.

#### [iOS](https://docs.sentry.io/platforms/unity/native-support.md#ios-1)

The SDK modifies the generated Xcode project to include the iOS SDK. It adds the initialization code to the `main.mm` and generates the options provided by the editor configuration window as `SentryOptions.m`. The SDK also copies the `SentryNativeBridge` that enables the C# layer to communicate with the iOS SDK. This means that there's no need to use the Unity [built-in crash reporting](https://docs.unity3d.com/ScriptReference/CrashReport.html) functionality.

The [iOS SDK](https://docs.sentry.io/platforms/apple/guides/ios.md) supports capturing Objective-C exceptions which are disabled in the generated Xcode project by default. Consider enabling them in the "Build Settings" tab by setting `GCC_ENABLE_OBJC_EXCEPTIONS` to true.

### [External Initialization](https://docs.sentry.io/platforms/unity/native-support.md#external-initialization)

When your game runs inside an iOS or Android app with Unity as a Library, the app owns the native SDK. The Unity SDK doesn't bundle it and attaches to the one the app initialized. On Android, a game running in a separate process initializes it there. Learn more in [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.md).

## [Desktop](https://docs.sentry.io/platforms/unity/native-support.md#desktop)

The native support is configured and enabled as early as possible by the C# layer, right after the Unity engine starts. This is slightly different from on mobile where we inject native initialization code that runs before the Unity engine runs.

Native support on Windows, Linux, and macOS with the Native backend writes files to disk. If you set `DisableFileWrite`, the SDK turns native support off on these platforms.

With an out-of-process crash handler (Crashpad on Windows, or the Native backend), `NativeHandlerPath` sets where the SDK looks for the handler executable. By default, it's next to the player executable. Learn more in [Options](https://docs.sentry.io/platforms/unity/configuration/options.md).

### [Windows](https://docs.sentry.io/platforms/unity/native-support.md#windows)

On Windows, the Unity SDK includes the [Native SDK](https://docs.sentry.io/platforms/native.md) with the Crashpad backend, for both 64-bit (x64) and 32-bit (x86) players. Windows native crashes are captured through minidumps. At the end of the build, the SDK copies `crashpad_handler.exe`, `crashpad_wer.dll`, and `sentry-native.dll` next to the player. Include all three files when you ship your game.

With the Native backend, which you can select with `options.Experimental.WindowsBackend = WindowsBackend.Native`, the SDK uploads crashes right away through the out-of-process `sentry-crash.exe` handler. The build copies `sentry-crash.exe`, `sentry-wer.dll`, and `sentry-native.dll` next to the player instead. Include all three files when you ship your game.

### [macOS](https://docs.sentry.io/platforms/unity/native-support.md#macos)

By default, native support on macOS relies on the [macOS SDK](https://docs.sentry.io/platforms/apple/guides/macos.md). Stackwalking happens in process. This Cocoa backend needs IL2CPP. With Mono, the SDK captures C# errors only.

With the Native backend, which you can select with `options.Experimental.MacosBackend = MacosBackend.Native`, the SDK uses the [Native SDK](https://docs.sentry.io/platforms/native.md) instead. It uploads crashes right away through the out-of-process `sentry-crash` handler, which the build copies next to the player, and it works with both IL2CPP and Mono.

### [Linux](https://docs.sentry.io/platforms/unity/native-support.md#linux)

On Linux the Unity SDK includes the [Native SDK](https://docs.sentry.io/platforms/native.md) with the Breakpad backend by default. A minidump is created in process and no handler executable is required. With the experimental Native backend, which you can select with `options.Experimental.LinuxBackend = LinuxBackend.Native`, the SDK uploads crashes right away through the out-of-process `sentry-crash` handler, which the build copies next to the player.

The Native SDK ships for `x86_64` and `ARM64`, and the build picks the one that matches the player's architecture. ARM64 is supported for dedicated servers built with IL2CPP on Unity 6000.3 and later. On both architectures, the Native SDK runs on distributions with older glibc versions, such as Ubuntu 22.04 and Debian 12.

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

Sentry requires [debug information files](https://docs.sentry.io/platforms/unity/data-management/debug-files.md) to symbolicate your crashes. The Unity SDK uploads them for you with [sentry-cli](https://docs.sentry.io/cli.md), so you don't need to run `sentry-cli` yourself. The SDK package includes `sentry-cli` for Windows, macOS, and Linux.

The automated upload is on by default, but it needs your credentials. Go to **Tools > Sentry**, open the **Debug Symbols** tab, and enter your [Auth Token](https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/) and the Project Name. Enter the Org Slug too, unless the auth token is an organization token. The SDK stores this configuration in `Assets/Plugins/Sentry/SentryCliOptions.asset`. Don't make this file publicly available. To set the auth token from code instead, for example from an environment variable in CI, see [Sentry CLI Options](https://docs.sentry.io/platforms/unity/configuration/options/cli-options.md#programmatic-configuration).

The SDK uploads debug symbols for release builds. To also upload them for development builds, enable **Upload Dev Symbols**.

Where the upload runs depends on the platform:

| Platform                                           | Where the upload runs                | Condition                                                                                   | Log                                                                                                                    |
| -------------------------------------------------- | ------------------------------------ | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
| Windows, macOS, Linux, Xbox, PlayStation 5, Switch | In the Unity Editor, after the build | Sentry enabled with a DSN                                                                   | Unity Console                                                                                                          |
| Android                                            | In the Gradle build                  | Sentry enabled, IL2CPP, and Android native support enabled                                  | `Logs/sentry-symbols-upload.log` in your Unity project, and `Logs/sentry-mapping-upload.log` with minification enabled |
| iOS                                                | In an Xcode build phase              | Sentry configured in **Tools > Sentry**, also when Sentry or iOS native support is disabled | `sentry-symbols-upload.log` in the root of the Xcode project                                                           |
| WebGL                                              | No upload                            |                                                                                             |                                                                                                                        |

If you export a Gradle or Xcode project instead of building the app in Unity, the upload runs when you build the exported project. For exported Gradle projects, the SDK doesn't write the log files; the upload output is in the Gradle build output. The exported Gradle project contains the `sentry-cli` for the operating system you exported it from, so build it on that operating system. The exported Xcode project contains the macOS `sentry-cli`.

Exported Xcode and Gradle projects contain a `sentry.properties` file with your auth token in plain text. Don't commit this file to version control. The file is in the root of the Xcode project and in the `launcher` module of the Gradle project, or in the `unityLibrary` module for [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.md).

### [iOS - dSYM](https://docs.sentry.io/platforms/unity/native-support.md#ios---dsym)

Debug information files on Apple platforms are called dSYMs. The SDK adds a build phase to the Xcode project that uploads the dSYMs from the build output when Xcode builds the app. You don't need to do anything else.

### [Android - ProGuard and R8](https://docs.sentry.io/platforms/unity/native-support.md#android---proguard-and-r8)

The SDK adds its ProGuard rules, `proguard-sentry-unity.pro`, to the Gradle project. If you enable **Minify** in **Player Settings > Publishing Settings**, the Gradle build also uploads the ProGuard mapping file, so Sentry can deobfuscate Java stack traces. With [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.md), the app that embeds the game minifies the code, so upload the mapping file from that app's build.

### [Manual Upload Using sentry-cli](https://docs.sentry.io/platforms/unity/native-support.md#manual-upload-using-sentry-cli)

If you don't want to rely on the automated upload for desktop and console builds, you can run `sentry-cli` from the command line. Use the executables in the SDK package, or follow the [sentry-cli documentation](https://docs.sentry.io/cli/installation.md) to install it globally. To upload your game's debug symbols, run:

```bash
sentry-cli --auth-token <your-sentry-auth-token> debug-files upload --il2cpp-mapping --org <your-org-slug> --project <your-project-slug> PATH_TO_BUILD_OUTPUT
```

`sentry-cli` scans `PATH_TO_BUILD_OUTPUT` recursively. Point it at the folder that contains your build and the `<Product>_BackUpThisFolder_ButDontShipItWithYourGame` and `<Product>_BurstDebugInformation_DoNotShip` folders that Unity creates next to it. These folders hold the IL2CPP output and the Burst debug information.

* `--il2cpp-mapping` uploads the line mapping that Sentry needs for [C# line numbers in IL2CPP builds](https://docs.sentry.io/platforms/unity/configuration/il2cpp.md). Leave it out for Mono builds.
* `--include-sources` is optional. It uploads your source code so Sentry can show [source context](https://docs.sentry.io/platforms/unity/data-management/debug-files/source-context.md).

The build folder doesn't contain the symbols of the Sentry native SDK. The automated upload also uploads them from the SDK package, so upload them too if you want symbolicated frames from the Sentry native SDK:

* Windows: the `.pdb` files in `Plugins/Windows/Sentry~/` or `Plugins/Windows/SentryNative~/`, in the `x64` or `x86` subfolder
* Linux: the `.dbg` and `.dbg.so` files in `Plugins/Linux/Sentry~/` or `Plugins/Linux/SentryNative~/`, in the `x86_64` or `ARM64` subfolder
* macOS: the `.dSYM` folders in `Plugins/macOS/Sentry~/` or `Plugins/macOS/SentryNative~/`
* Consoles: your project's `Assets/Plugins/Sentry/` folder, and for a Nintendo Switch NSP build, `Library/Bee/artifacts/<target>PlayerBuildProgram`, because the NSP packs the assemblies

These paths are relative to the SDK package. If you installed the SDK with UPM, the package is in `Library/PackageCache/` in your Unity project.

For Android and iOS, rely on the automated upload. On Android, it uploads the symbols from `Library/Bee/` in your Unity project. On iOS, it uploads them from the Xcode build output.

## [Store Minidumps as Attachments](https://docs.sentry.io/platforms/unity/native-support.md#store-minidumps-as-attachments)

[Minidumps](https://docs.sentry.io/platforms/native/guides/minidumps.md#what-is-a-minidump) may contain sensitive information about the target system, such as environment variables, local pathnames, or in-memory representations of input fields, including passwords. By default, Sentry only uses minidump files to create events and immediately drops them. All sensitive information is stripped from the resulting events.

All attachment types, including log files, screenshots and minidumps (if you enable Store Minidumps As Attachments), are retained for 30 or 90 days, based on [your plan's data retention period](https://docs.sentry.io/security-legal-pii/security/data-retention-periods.md#default-data-retention-by-plan) when sent to Sentry. Note that Sentry does not apply data scrubbing to attachments.

☝ This feature is supported on Windows, Linux, and macOS with the Native backend.

### [Enabling Minidump Storage](https://docs.sentry.io/platforms/unity/native-support.md#enabling-minidump-storage)

You can enable *Store Minidumps As Attachments* in your [organization](https://sentry.io/orgredirect/organizations/:orgslug/settings/security-and-privacy/) or [project settings](https://sentry.io/orgredirect/organizations/:orgslug/settings/projects/:projectId/security-and-privacy/) under **Security & Privacy**. By default, this setting is disabled. Determine the maximum number of crash reports that will be stored per issue; disabled, unlimited, or maximum per issue:

If you set a limit per issue, as in the example above, a limit of 5, Sentry will store the first 5 attachments associated with this issue, but drop any that follow. To make room for additional attachments, delete them. Sentry will then accept attachments until the limit is reached again.

## Pages in this section

- [Unity as a Library](https://docs.sentry.io/platforms/unity/native-support/unity-as-a-library.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.
