Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#unitytips: Changing the style of the Hierarchy Window Group Header -
using System;
using System.IO;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// Hierarchy Window Group Header
/// </summary>
public static class HierarchyWindowGroupHeader
static readonly HierarchyWindowGroupHeaderSettings _settings;
static readonly GUIStyle _style;
static HierarchyWindowGroupHeader()
_settings = HierarchyWindowGroupHeaderSettings.Instance;
_style = new GUIStyle();
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI;
static void UpdateStyle()
_style.fontSize = _settings.FontSize;
_style.fontStyle = _settings.FontStyle;
_style.alignment = _settings.Alignment;
_style.normal.textColor = _settings.TextColor;
static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject != null &&, StringComparison.Ordinal))
EditorGUI.DrawRect(selectionRect, _settings.BackgroundColor);
EditorGUI.LabelField(selectionRect,, "").ToUpperInvariant(), _style);
public class HierarchyWindowGroupHeaderSettings : ScriptableObject
public UnityEvent Changed;
public string NameStartsWith = "---";
public string RemoveString = "-";
public FontStyle FontStyle = FontStyle.Bold;
public int FontSize = 14;
public TextAnchor Alignment = TextAnchor.MiddleCenter;
public Color TextColor =;
public Color BackgroundColor = Color.gray;
static HierarchyWindowGroupHeaderSettings _instance;
public static HierarchyWindowGroupHeaderSettings Instance => _instance ?? (_instance = LoadAsset());
void OnValidate()
private static HierarchyWindowGroupHeaderSettings LoadAsset()
var path = GetAssetPath();
var asset = AssetDatabase.LoadAssetAtPath<HierarchyWindowGroupHeaderSettings>(path);
if (asset == null)
asset = CreateInstance<HierarchyWindowGroupHeaderSettings>();
AssetDatabase.CreateAsset(asset, path);
return asset;
private static string GetAssetPath([CallerFilePath] string callerFilePath = null)
var folder = Path.GetDirectoryName(callerFilePath);
folder = folder.Substring(folder.LastIndexOf(@"\Assets\", StringComparison.Ordinal) + 1);
folder = folder.Substring(folder.LastIndexOf("/Assets/", StringComparison.Ordinal) + 1);
return Path.Combine(folder, "HierarchyWindowGroupHeaderSettings.asset");

This comment has been minimized.

Copy link

@razzraziel razzraziel commented Aug 19, 2019

You should seperate the classes because scriptable objects needs their own script file to locate.

Otherwise you'll continue to get "No script asset for HierarchyWindowGroupHeaderSettings. Check that the definition is in a file of the same name" warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment