---
title: "View Hierarchy"
description: "Learn more about debugging the view hierarchy when an error occurs. Sentry pairs the view hierarchy representation with the original event, giving you additional insight into issues."
url: https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy/
---

# View Hierarchy for Unity

Sentry makes it possible to render a JSON representation of the scene of an error and includes it as an [attachment](https://docs.sentry.io/platforms/unity/enriching-events/attachments.md).

The SDK captures the view hierarchy of the active scene only, and only for events captured on the main thread. Events captured on background threads and native crashes don't get one. It works in the Unity Editor and on WebGL too.

## [Enabling View Hierarchy Attachments](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#enabling-view-hierarchy-attachments)

View hierarchy debugging is an opt-in feature. You can enable attaching the view hierarchy as shown below through **Tools > Sentry**:

Or, like so, if you're [configuring things programmatically](https://docs.sentry.io/platforms/unity/configuration/options/programmatic-configuration.md):

```csharp
options.AttachViewHierarchy = true;
```

## [Customize View Hierarchy Capturing](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#customize-view-hierarchy-capturing)

Because capturing view hierarchy can be a resource-intensive operation as the SDK traverses the scene at the time of an error, there are several controls available to you.

### [MaxViewHierarchyRootObjects](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#MaxViewHierarchyRootObjects)

| Type    | `int` |
| ------- | ----- |
| Default | `100` |

Allows you to limit the amount of gameobjects to be traversed and included in the view hierarchy.

### [MaxViewHierarchyDepth](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#MaxViewHierarchyDepth)

| Type    | `int` |
| ------- | ----- |
| Default | `10`  |

Allows you to limit the maximum depth of child-gameobject the SDK will attempt to traverse to include in the view hierarchy.

### [MaxViewHierarchyObjectChildCount](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#MaxViewHierarchyObjectChildCount)

| Type    | `int` |
| ------- | ----- |
| Default | `20`  |

Allows you to limit the maximum count of child-gameobjects per individual gameobject the SDK will attempt to include in the view hierarchy.

These are also available for programmatic configuration on the options object:

```csharp
options.MaxViewHierarchyDepth = 10;
options.MaxViewHierarchyRootObjects = 100;
options.MaxViewHierarchyObjectChildCount = 20;
```

To decide whether an event gets a view hierarchy, use `SetBeforeCaptureViewHierarchy`. Return `false` to skip it:

```csharp
options.SetBeforeCaptureViewHierarchy(sentryEvent =>
{
    // Don't capture the view hierarchy for warnings
    return sentryEvent.Level != SentryLevel.Warning;
});
```

## [Modifying or Discarding the View Hierarchy](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#modifying-or-discarding-the-view-hierarchy)

To edit the view hierarchy before it's sent, or to discard it, use `SetBeforeSendViewHierarchy`. Return `null` to discard it:

```csharp
options.SetBeforeSendViewHierarchy((viewHierarchy, sentryEvent) =>
{
    // The root node is the scene, and its children are the root GameObjects
    foreach (var scene in viewHierarchy.Windows)
    {
        scene.Children.RemoveAll(node => node.Type == "AccountScreen");
    }

    return viewHierarchy;
});
```

## [Viewing View Hierarchy Attachments](https://docs.sentry.io/platforms/unity/enriching-events/view-hierarchy.md#viewing-view-hierarchy-attachments)

View hierarchies appear in the "Attachments" tab, where you can view all attachments, as well as associated events. Click the event ID to open the [Issue Details](https://docs.sentry.io/product/issues/issue-details.md) page of that specific event.

On the **Issue Details** page, you can interact with the view hierarchy attachment in a section called "View Hierarchy". This section represents the state of your scene at the time of an error event. There are two displays: a tree view, and detailed view for a selected node. You can select nodes in the tree to view the properties collected by the SDK. The SDK will report on the following keys for each node in the view:

* `tag` The gameobject's tag
* `position` The gameobject's position
* `rotation` The gameobject's rotation in euler angles
* `scale` The gameobject's local scale
* `active` Whether the gameobject itself was active (`activeSelf`)
* `extras` The type names of all components attached to the gameobject

This feature can be used as an exploratory tool to debug reference issues, or gain a better understanding of the relationship between gameobjects.
