# HierarchyViewCellDescriptor

> Provides a cell descriptor used to register a new HierarchyViewCell for a specific HierarchyNodeTypeHandler type in the Hierarchy. Use this class to create custom UI to edit or display data for a node in a HierarchyViewCell that corresponds to a HierarchyViewColumn.

## Definition

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

```csharp
public sealed class HierarchyViewCellDescriptor
```

## Remarks

The following example creates a column in the Hierarchy window that displays the icons of each component attached to a GameObject. It uses `HierarchyViewCellDescriptor` to register a custom cell binding for the `HierarchyGameObjectHandler` type that displays the component icons in the custom Hierarchy column.

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                                                                                                                                                                                                                                                                                                                                              |
| ----------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [BindCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/bindcell.md)         | Callback triggered when the [HierarchyViewCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcell.md) is bound.                                                                                                                                                                                                                          |
| [BindColumn](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/bindcolumn.md)     | Callback triggered when the column containing a [HierarchyViewCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcell.md) generated by this descriptor is bound to the [HierarchyView](/engine/6000.6/script-reference/unity/hierarchy/hierarchyview.md).                                                                                |
| [UnbindCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/unbindcell.md)     | Callback triggered when the [HierarchyViewCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcell.md) is unbound. The [VisualElement](/engine/6000.6/script-reference/unityengine/uielements/visualelement.md) content of the cell is automatically cleared. Use this callback to dispose of custom resources or unregister from events. |
| [UnbindColumn](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/unbindcolumn.md) | Callback triggered when the column containing a [HierarchyViewCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcell.md) generated by this descriptor is unbound from the [HierarchyView](/engine/6000.6/script-reference/unity/hierarchy/hierarchyview.md).                                                                            |

## Constructors

| Constructor                                                                                                                                   | Description                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [HierarchyViewCellDescriptor(System.String,System.Type)](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/ctor.md) | Creates a new [HierarchyViewCellDescriptor](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor.md). |

## Properties

| Property                                                                                                            | Description                                                                                                                                                  |
| ------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [ClearCellContent](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/clearcellcontent.md) | If true, the children of the [HierarchyViewCell](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcell.md) are deleted when the cell is unbound. |
| [ColumnId](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/columnid.md)                 | Gets the column identifier that this cell is registered to.                                                                                                  |
| [HandlerType](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/handlertype.md)           | Gets the [HierarchyNodeTypeHandler](/engine/6000.6/script-reference/unity/hierarchy/hierarchynodetypehandler.md) type used to manage the node of this cell.  |
| [UserData](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/userdata.md)                 | Gets or sets custom user data associated with this descriptor.                                                                                               |

## Methods

| Method                                                                                                          | Description                                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [ValidForColumn](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcelldescriptor/validforcolumn.md) | Validates that a [HierarchyViewColumnDescriptor](/engine/6000.6/script-reference/unity/hierarchy/hierarchyviewcolumndescriptor.md) is valid for this cell descriptor. |
