What is the best way to draw icons in Unity's Hierarchy window?


What is the most efficient way to draw an icon/image in Unity’s Hierarchy window to hopefully minimize the amount that Unity may slow down? I’m currently using EditorGUI.LabelField() with predefined GUIContents that grab an icon using EditorGUIUtility.IconContent().


I’ve recently been working on making my own “skin” for Unity’s Hierarchy window. Everything has been fine and was turning out well until I started drawing icons next to objects. Here is what it is at now:


The problem though is when I draw the icons (on the left), and there are a lot of objects in the Hierarchy window. Unity’s editor begins to slow down at this point. Which I get. Drawing a bunch of images like this can be taxing. It is only with the icons though. If I comment out the one line of code that is drawing them, it all runs smooth. I don’t like this. I feel like it shouldn’t slow down all that much, or there should be a way to draw the icons more efficiently. Here is a little code snippet of how I’m drawing the icons:

// Grab icon GUIContent from dictionary in HierarchyDefaultConfigSettings
GUIContent iconGUIContent = HierarchyDefaultConfigSettings.defaultLabelIconMapping[labelDetails.name];

// Make and adjust rect for icon
Rect iconRect = new Rect(fullSelectionRect);
iconRect.width = EditorGUIUtility.singleLineHeight;
iconRect.height = EditorGUIUtility.singleLineHeight;
iconRect.height -= 2;
iconRect.y += 1;
iconRect.x += 1;

// Drawing of icon (CAUSES EDITOR TO SLOW DOWN! :c)
EditorGUI.LabelField(iconRect, iconGUIContent, ""); 

It’s not like I’m creating the GUIContents inside of this main function that is doing the drawing of the labels and such. Also, the main drawing function is attached to the EditorApplication.hierarchyWindowItemOnGUI delegate just for more info.

Hmm, welp, gonna “answer” my own question here. It seems like this helps greatly:

EditorGUI.LabelField(iconRect, iconGUIContent);

Just removing the empty string from LabelField made the performance much better while shrinking the icons a bit I guess. Just gotta increase the Rect size to make up for it? I dunno. This works for me for now.