Skip to content

feat(Unity): Editor Facelift #13514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ On platforms that do no support multithreading the ANR detection falls back to r

ANR detection is enabled by default in Sentry, but you can opt-out through the editor window by going to `Tools -> Sentry -> Advanced -> ANR Detection`. You can also set the ANR timeout there.

![ANR Detection](./img/unity-anr.jpg)
![ANR Detection](./img/unity-anr.png)

You can also opt out by disabling the integration.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
160 changes: 66 additions & 94 deletions docs/platforms/unity/configuration/options/index.mdx

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions docs/platforms/unity/enriching-events/screenshots/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,28 @@ This feature is only available for SDKs with a user interface, like the ones for

## Enabling Screenshots

Because screenshots may contain <PlatformLink to="/data-management/sensitive-data/">PII</PlatformLink>, they are an opt-in feature. You can enable screenshots as shown below:
Because screenshots may contain <PlatformLink to="/data-management/sensitive-data/">PII</PlatformLink>, they are an opt-in feature. You can enable screenshots as shown below through **Tools > Sentry**:

<PlatformContent includePath="enriching-events/attach-screenshots" />
![Options Screenshot Configuration](./img/editor-window.png)

Or, like so, if you're [configuring things programatically](/platforms/unity/configuration/options/):

```csharp {tabTitle:ScriptableOptionsConfiguration}
options.AttachScreenshot = true;
```

## Screenshot capture mechanism

Since the Unity SDK internally consists of multiple SDKs, the mechanism with which a screenshot gets captured depends on where the error originates.

- C# errors from within your game will be captured through Unity's built-in [ScreenCapture](https://docs.unity3d.com/ScriptReference/ScreenCapture.html). This means that screenshots only contain things visible within your game. Overlays on top of your game will not be visible.
- Native errors get captured by their respective SDK. If you're using a native plugin to display an overlay and an error occurs then that SDK will try to capture a screenshot that contains the overlay.

<Alert>

Screenshots might contain PII of your app. For example, if your game has a registration form and an error happens while the form is being displayed.

</Alert>

## Viewing Screenshots

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ This feature only applies to SDKs with a user interface, such as the ones for mo

## Enabling View Hierarchy Attachments

View hierarchy debugging is an opt-in feature. You can enable it via the configuration editor `Enrichment -> Attach Hierarchy` or programmatically:
View hierarchy debugging is an opt-in feature. You can enable attaching the view hierarchy as shown below through **Tools > Sentry**:

```csharp
![Options Screenshot Configuration](./img/editor-window.png)

Or, like so, if you're [configuring things programatically](/platforms/unity/configuration/options/):

```csharp {tabTitle:ScriptableOptionsConfiguration}
options.AttachViewHierarchy = true;
```

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions docs/platforms/unity/usage/automatic-error-capture/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
title: Automatic Error Capture
sidebar_order: 10
description: "Learn more about how the SDK automatically captures errors and sends them to Sentry."
---

The Sentry SDK for Unity provides both automatic and manual error capturing capabilities. This page focuses on the **automatic error capture** through Unity's logging system integrations. For information on manually capturing errors and messages, see the [Usage documentation](/platforms/unity/usage/).

## Automatic Error Capture

The Unity SDK relies on two integrations to automatically capture errors: `UnityLogHandlerIntegration` and `UnityApplicationLoggingIntegration`. While they sound similar, they serve different purposes.

## UnityLogHandlerIntegration

The SDK uses the `UnityLogHandlerIntegration` to hook into Unity's logging system. From there it receives all log messages that are logged via the `Debug.Log`, `Debug.LogWarning`, and `Debug.LogError` methods. By default, the SDK adds these log messages as breadcrumbs to future events. The SDK will also automatically capture messages logged via `Debug.LogError` as error events and send them to Sentry. This behaviour can be disabled by unchecking the automatic capture of `Debug.LogError` on the `Logging` tab in the editor (Tools->Sentry), or programmatically, by setting the `CaptureLogErrorEvents` option to `false` in the [configure callback](/platforms/unity/configuration/options/programmatic-configuration).

### Stack Trace Support & Line Numbers

If [configured](https://docs.unity3d.com/6000.0/Documentation/Manual/stack-trace.html), Unity will include the stack traces with the log messages as raw strings. The SDK is able to parse and display this stack trace in the issue details page.

If you're using Unity 6 or newer, you have the option to to enable the source code line numbers in the [player settings](https://docs.unity3d.com/6000.0/Documentation/Manual/il2cpp-managed-stack-traces.html). These line numbers are then part of the stringified stack trace and will be parsed by the SDK.

<Alert>
Known Limitation: In versions older than Unity 6, the SDK is unable to provide line numbers for events captured through `Debug.LogError`. The SDK has only the strigified stack trace provided by Unity to work with and since there is no native exception available at the time of logging, Sentry can't symbolicate the stack trace on the server side either.
</Alert>

## UnityApplicationLoggingIntegration

The SDK uses the `UnityApplicationLoggingIntegration` to add its own log handler right before Unity's logging system. It then passes the logs back to Unity. This allows the SDK to capture errors through the `Application.logMessageReceived` method. All handled exceptions - such as those captured via `Log.LogException` calls - and unhandled exceptions end up on that call and are captured by the SDK. These messages contain the actual exception object. This allows the SDK to call into the IL2CPP backend and connect this managed exception to the native exception, allowing for server side symbolication. You can read more about the IL2CPP error integration works [here](/platforms/unity/configuration/il2cpp).
12 changes: 11 additions & 1 deletion docs/platforms/unity/usage/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ Key terms:
- An _event_ is one instance of sending data to Sentry. Generally, this data is an error or exception.
- An _issue_ is a grouping of similar events.
- The reporting of an event is called _capturing_.
When an event is captured, its sent to Sentry.
When an event is captured, it's sent to Sentry.

</Alert>

By default, the Sentry Unity SDK automatically captures errors through Unity's logging system. For details on this automatic error capture, see the [Automatic Error Capture documentation](/platforms/unity/usage/logging-integration/).

In addition to automatic capture, you can manually capture errors, exceptions, and messages as described below.

The most common form of capturing is to capture errors. What can be captured as an error varies by platform. In general, if you have something that looks like an exception, it can be captured. For some SDKs, you can also omit the argument to <PlatformIdentifier name="capture-exception" /> and Sentry will attempt to capture the current exception. It is also useful for manual reporting of errors or messages to Sentry.

While capturing an event, you can also record the breadcrumbs that lead up to that event. Breadcrumbs are different from events: they will not create an event in Sentry, but will be buffered until the next event is sent. Learn more about breadcrumbs in our <PlatformLink to="/enriching-events/breadcrumbs/">Breadcrumbs documentation</PlatformLink>.
Expand All @@ -32,3 +36,9 @@ Another common operation is to capture a bare message. A message is textual info
Messages show up as issues on your issue stream, with the message as the issue name.

<PlatformContent includePath="capture-message" />

<Alert>

By default, the SDK only provides a stack trace for captured exceptions. To provide a stack trace in message events, captured either through `SentrySdk.CaptureMessage` or `Debug.LogError`, you need to set `AttachStacktrace` to `true` in the `Logging` tab in the editor (Tools->Sentry).

</Alert>
2 changes: 1 addition & 1 deletion docs/platforms/unity/usage/set-level/index.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: Set the Level
description: "The level - similar to logging levels - is generally added by default based on the integration. You can also override it within an event."
sidebar_order: 5
sidebar_order: 20
---

The level - similar to logging levels - is generally added by default based on the integration. You can also override it within an event.
Expand Down
Binary file not shown.
Binary file not shown.
22 changes: 0 additions & 22 deletions platform-includes/enriching-events/attach-screenshots/unity.mdx

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
2 changes: 1 addition & 1 deletion platform-includes/getting-started-verify/unity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TestMonoBehaviour : MonoBehaviour
{
Debug.Log("Captured Log"); // Breadcrumb
Debug.LogWarning("Captured Warning"); // Breadcrumb
Debug.LogError("Captured Error"); // Captured Error
Debug.LogError("Captured Error"); // Captured Error by default

// This will throw an unhandled Null Reference Exception
testObject.GetComponent<Transform>(); // Captured error
Expand Down