# RowContainer

> Gets the VisualElement that represents the entire row container of this HierarchyViewItem.

## Definition

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

```csharp
public VisualElement RowContainer { get; }
```

### Remarks

The following example changes the row background color of the Hierarchy window for GameObjects that have an `Enemy` component attached to them. It uses `RowContainer` to apply a custom USS class to the entire row.

The example requires two USS files for theme-based styling: `ChangeRowColor_dark.uss` for the Dark theme, and `ChangeRowColor_light.uss` for the Light theme.

It also requires a custom MonoBehaviour script called `Enemy.cs`.

To use this example:

1. Save the script in a folder called `Assets/Editor/ChangeRowColor`. 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.
2. Copy the styles from the USS examples on this page. Save them in USS files called `ChangeRowColor_dark.uss` and `ChangeRowColor_light.uss` in the same `Assets/Editor/ChangeRowColor` folder.
3. Save the `Enemy.cs` script outside of an `Editor` folder, because MonoBehaviour scripts in an `Editor` folder can't be attached to GameObjects.
4. Add the `Enemy` component to a GameObject. The background color of the row of that GameObject changes in the Hierarchy window.

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

namespace Unity.HierarchySamples.Editor
{
    class ChangeRowColor
    {
        const string k_RowColorUssClassName = "gameobject--enemy";

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

        static void OnBindView(HierarchyWindow window, HierarchyView view)
        {
            // Loads a theme-specific stylesheet for light or dark Editor skin.
            view.styleSheets.Add(AssetDatabase.LoadAssetAtPath<StyleSheet>($"Assets/Editor/ChangeRowColor/ChangeRowColor{(EditorGUIUtility.isProSkin ? "_dark" : "_light")}.uss"));
        }

        static void OnBindViewItem(HierarchyWindow window, HierarchyView view, HierarchyViewItem item)
        {
            if (item.Handler is not HierarchyGameObjectHandler handler)
                return;

            GameObject gameObject = handler.GetGameObject(item.Node);
            // Checks if the GameObject has an Enemy component attached to it. You can replace "Enemy" with your own MonoBehaviour class name.
            item.RowContainer.EnableInClassList(k_RowColorUssClassName, gameObject.TryGetComponent<Enemy>(out _));
        }
    }
}
```

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

```csharp
.gameobject--enemy {
    background-color: #7a2d2d;
}
```

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

```csharp
.gameobject--enemy {
    background-color: #8f6464;
}
```

The following example shows the `Enemy` component that the ChangeRowColor example uses.

```csharp
using UnityEngine;

namespace Unity.HierarchySamples
{
    public class Enemy : MonoBehaviour
    {
        // Marker component used by ChangeRowColor and CustomContextMenuAction samples.
    }
}
```
