---
title: "Automatic Error Capture"
description: "Learn more about how the SDK automatically captures errors and sends them to Sentry."
url: https://docs.sentry.io/platforms/unity/usage/automatic-error-capture/
---

# Automatic Error Capture for Unity

The Sentry SDK for Unity provides both automatic and manual error capturing capabilities on all layers of your application. This page focuses on the **automatic error capture**. For information on manually capturing errors and messages, see the [Usage documentation](https://docs.sentry.io/platforms/unity/usage.md).

## [Automatic Error Capture through Unity's Logging System](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#automatic-error-capture-through-unitys-logging-system)

The Unity SDK automatically captures errors reported through Unity's logging system. How an event is captured depends on the logging method you use.

### [`Debug.LogError` and `Debug.LogAssertion`](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#debuglogerror-and-debuglogassertion)

`Debug.LogError` and `Debug.LogAssertion` are captured as error-level message events. A failed `Debug.Assert` is captured the same way. Unity only runs `Debug.Assert` and `Debug.LogAssertion` in the editor and in development builds, so release builds don't send them. Disable automatic capture in **Tools -> Sentry -> Logging**, or set `CaptureLogErrorEvents` to `false` in the [configure callback](https://docs.sentry.io/platforms/unity/configuration/options/programmatic-configuration.md).

Enable `AttachStacktrace` to include and parse the stack trace Unity provides with the log. On platforms other than WebGL, Unity 6 or later can include source lines in that stack trace when you enable source code line numbers in [Player Settings](https://docs.unity3d.com/6000.0/Documentation/Manual/il2cpp-managed-stack-traces.html).

In versions older than Unity 6, `Debug.LogError` stack traces do not include source line numbers.

### [`Debug.LogException`](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#debuglogexception)

On platforms other than WebGL, `Debug.LogException` captures the exception as an error event. If the exception was thrown before logging, its stack trace is included. A newly constructed exception has no stack trace, so `Debug.LogException(new Exception("message"))` reports only its type and message.

Events captured through `Debug.LogException` are marked as unhandled. Unity doesn't identify whether an exception was explicitly logged or was unhandled. On WebGL, the SDK captures the stack trace Unity logs; see [known limitations](https://docs.sentry.io/platforms/unity/troubleshooting/known-limitations.md#webgl-support).

### [Caught Exceptions](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#caught-exceptions)

Use `SentrySdk.CaptureException` for an exception you caught. This preserves its stack trace and reports it as handled:

```csharp
try
{
    ThrowException();
}
catch (Exception e)
{
    SentrySdk.CaptureException(e);
}
```

For IL2CPP line-number requirements, see [IL2CPP Line Numbers](https://docs.sentry.io/platforms/unity/configuration/il2cpp.md).

### [Limit Repeated Errors](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#limit-repeated-errors)

A game can log the same error every frame. To drop the repeats, turn on [event throttling](https://docs.sentry.io/platforms/unity/configuration/event-debouncing.md).

### [Disable Automatic Capture](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#disable-automatic-capture)

To stop capturing errors from Unity's logging system, call these in your [options configuration script](https://docs.sentry.io/platforms/unity/configuration/options/programmatic-configuration.md):

* [`DisableUnityLoggingIntegration()`](https://docs.sentry.io/platforms/unity/configuration/options.md#DisableUnityLoggingIntegration) stops capturing `Debug.LogError` and `Debug.LogAssertion` calls, along with log breadcrumbs and structured logs.
* [`DisableUnhandledExceptionCapture()`](https://docs.sentry.io/platforms/unity/configuration/options.md#DisableUnhandledExceptionCapture) stops capturing exceptions that reach Unity's log handler: uncaught exceptions and `Debug.LogException` calls, on every platform including WebGL.

```csharp
public override void Configure(SentryUnityOptions options)
{
    options.DisableUnityLoggingIntegration();
    options.DisableUnhandledExceptionCapture();
}
```

The SDK still captures unhandled exceptions from .NET's `AppDomain` and unobserved tasks. To stop those, call `options.DisableAppDomainUnhandledExceptionCapture()` and `options.DisableUnobservedTaskExceptionCapture()`.

## [Automatic Error Capture on the Native Layer](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#automatic-error-capture-on-the-native-layer)

The Unity SDK also supports automatic error capture on the native layer. This is enabled by default and works through the respective native SDKs for each platform.

For more information on how to configure the native SDK, see the [Native SDK documentation](https://docs.sentry.io/platforms/unity/native-support.md).

## [Connecting Errors Captured on Different Layers](https://docs.sentry.io/platforms/unity/usage/automatic-error-capture.md#connecting-errors-captured-on-different-layers)

The Sentry SDKs already have the ability to connect events in a distributed system through the use of a trace. You can read more about how this works in the [Tracing documentation](https://docs.sentry.io/platforms/unity/tracing.md).

The Unity SDK adds trace context (including a trace ID) to errors and shares this information with underlying native SDKs. This allows Sentry to automatically connect related events between different layers when errors occur.

On the issues details page, you will see this as errors being connected within the Trace Preview. The example below is taken from an game running on Android and shows a C# error being connected to an exception in Kotlin and a crash in C.

Without tracing, the SDK creates one trace at startup, and every error in the session shares it. With tracing enabled, each transaction (startup, scene load, or one you start yourself and set on the scope) has its own trace, and errors that happen while it runs join that trace. When a transaction finishes, the SDK starts a new trace.
