# HierarchyViewColumnDescriptor

> Provides a column descriptor used to register a new column in the HierarchyView and to control the display and customization of this column.

## Definition

* **Type:** Class
* **Namespace:** [Unity.Hierarchy](/engine/6000.6/script-reference/unity/hierarchy.md)
* **Assembly:** UnityEngine.HierarchyModule

```csharp
public sealed class HierarchyViewColumnDescriptor
```

## Remarks

The following example creates a column in the Hierarchy window that displays the icons of each component attached to a GameObject. It uses `HierarchyViewColumnDescriptor` to register the column, configure its properties, and pair the column with a `HierarchyViewCellDescriptor` to populate each cell.

The example requires the USS file `ComponentsColumn.uss`. To use this example, save the script and USS file in a folder called `Assets/Editor/ComponentsColumn`. Scripts in an `Editor` folder can use the Hierarchy module API without additional setup. If you save the script outside of an `Editor` folder, you must enable the Hierarchy built-in module in the **Package Manager** window, which also adds the module to your Player builds.

After adding the script to your project, enable the new **Components** column in the Hierarchy window for it to display.

```csharp
using Unity.Hierarchy;
using Unity.Hierarchy.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.Pool;
using UnityEngine.UIElements;

namespace Unity.HierarchySamples.Editor
{
    class ComponentsColumn
    {
        const string k_ColumnId = "GameObject/Components";
        const string k_IconRowUssClass = "component-icon-row";
        const string k_ComponentIconUssClass = "component-icon";

        static readonly ObjectPool<Image> s_ImagePool = new(() => new Image());

        [InitializeOnLoadMethod]
        static void Initialize()
        {
            HierarchyWindow.BindView += OnBindView;
        }

        static void OnBindView(HierarchyWindow window, HierarchyView view)
        {
            view.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>("Assets/Editor/ComponentsColumn/ComponentsColumn.uss"));
        }

        [HierarchyViewColumnDescriptor(k_ColumnId)]
        internal static void CreateColumnDesc(HierarchyViewColumnDescriptor desc)
        {
            desc.Title = "Components";
            desc.Tooltip = "Show all Components of GameObject";
            desc.DefaultPriority = 1000;
            desc.DefaultWidth = 100;
        }

        [HierarchyViewCellDescriptor(k_ColumnId, typeof(HierarchyGameObjectHandler))]
        internal static void CreateGameObjectCellDesc(HierarchyViewCellDescriptor desc)
        {
            desc.BindCell = cell =>
            {
                // It's safe to cast cell.Handler to HierarchyGameObjectHandler here. This method has the
                // HierarchyViewCellDescriptor attribute on it with the HierarchyGameObjectHandler specified to it,
                // so this method is called only for nodes created by the HierarchyGameObjectHandler.
                HierarchyGameObjectHandler handler = (HierarchyGameObjectHandler)cell.Handler;
                GameObject gameObject = handler.GetGameObject(cell.Node);
                Component[] components = gameObject.GetComponents<Component>();
                VisualElement iconRow = cell.Q(className: k_IconRowUssClass);
                if (iconRow == null)
                {
                    iconRow = new VisualElement();
                    iconRow.AddToClassList(k_IconRowUssClass);
                    iconRow.style.flexDirection = FlexDirection.Row;
                    cell.Add(iconRow);
                }
                else
                {
                    iconRow.Query<Image>(className: k_ComponentIconUssClass).ForEach(el =>
                    {
                        el.RemoveFromHierarchy();
                        s_ImagePool.Release(el);
                    });
                }

                foreach (Component comp in components)
                {
                    Texture2D icon = AssetPreview.GetMiniThumbnail(comp);
                    if (!icon)
                        continue;

                    Image iconEl = s_ImagePool.Get();
                    iconEl.AddToClassList(k_ComponentIconUssClass);
                    iconEl.image = icon;
                    iconRow.Add(iconEl);
                }

                cell.IsDefaultValue = false;
            };
        }

    }
}
```

The following example shows how to style `ComponentsColumn.uss`.

```csharp
.component-icon-row {
    justify-content: flex-end;
}

.component-icon {
    width: 14px;
    height: 14px;
    margin-left: 3px;
    margin-top: 3px;
}
```

## Fields

| Value                                                                                                           | Description                                                                                                                                     |
| --------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| [BindColumn](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/bindcolumn.md)       | Callback triggered when the column is built and shown in the [HierarchyView](/engine/6000.6/script-reference/unity/hierarchy/hierarchyview.md). |
| [BindHeader](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/bindheader.md)       | Callback that binds a custom header.                                                                                                            |
| [DestroyHeader](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/destroyheader.md) | Callback triggered when the window is closed.                                                                                                   |
| [MakeHeader](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/makeheader.md)       | Callback that creates a custom header. If null, the default header displays both the icon and text of the Name field.                           |
| [UnbindColumn](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/unbindcolumn.md)   | Callback triggered when the column is about to be destroyed.                                                                                    |
| [UnbindHeader](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/unbindheader.md)   | Callback triggered when the header is about to be destroyed or after domain reload.                                                             |

## Constructors

| Constructor                                                                                                                           | Description                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [HierarchyViewColumnDescriptor(System.String)](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/ctor.md) | Creates a new [HierarchyViewColumnDescriptor](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor.md). |

## Properties

| Property                                                                                                                | Description                                                                                                                                                                                                                                                                                                                                |
| ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [DefaultPriority](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/defaultpriority.md)     | Gets or sets the priority used to sort column order. A priority of 0 corresponds to the Name column in the [Hierarchy](/engine/6000.6/script-reference/unity/hierarchy/hierarchy.md). A negative priority places the column to the left of the Name column. A positive priority places the column to the right of the default Name column. |
| [DefaultVisibility](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/defaultvisibility.md) | Gets or sets whether the column is initially visible.                                                                                                                                                                                                                                                                                      |
| [DefaultWidth](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/defaultwidth.md)           | Gets or sets the default width when first instantiating the column. If you set it to a negative value, the column is assigned an arbitrary width.                                                                                                                                                                                          |
| [Icon](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/icon.md)                           | Gets or sets the icon displayed in the header of the column.                                                                                                                                                                                                                                                                               |
| [Id](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/id.md)                               | Gets the column identifier. [HierarchyViewCellDescriptor](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor.md) instances use this identifier to register themselves with the column.                                                                                                                            |
| [Title](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/title.md)                         | Gets or sets the display name of the column. If null, the header is empty unless it contains an icon.                                                                                                                                                                                                                                      |
| [Tooltip](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/tooltip.md)                     | Gets or sets the tooltip shown when the user hovers over the header of this column.                                                                                                                                                                                                                                                        |
| [UserData](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor/userdata.md)                   | Gets or sets user data associated with this descriptor.                                                                                                                                                                                                                                                                                    |
