- Home /
how to change gameobject color in hierarchy for highlight purposes.
I want to highlight a particular gameobject in hierarchy to make it important, so that i can find it at aglance. Any code guys???
Answers doesn't work like this, you come with code and we will help you fix issues with it.
Answer by icardenas_unity · Oct 29, 2019 at 07:51 PM
I know it is too late .. but ... i hope this work for anyone :) https://www.youtube.com/watch?v=x433HgFheeE ,I know it is too much late but... i hope it works for some body else :) https://www.youtube.com/watch?v=x433HgFheeE
Answer by sumit47 · Jun 29, 2017 at 04:51 AM
I used this code working properly but working only on gameobject selection , while i want it stable so that i can find my important gameobject at a glance.
using UnityEngine; using System.Collections; using UnityEditor; [InitializeOnLoad] public class MyHierarchyPanel { static MyHierarchyPanel () { EditorApplication.hierarchyWindowItemOnGUI += hierarchWindowOnGUI;
}
static void hierarchWindowOnGUI (int instanceID, Rect selectionRect)
{
//change bg and font color
GUI.backgroundColor = Color.black;
GUI.contentColor =Color.white;
// get objects
Object o = EditorUtility.InstanceIDToObject(instanceID);
GameObject g = (GameObject)o as GameObject;
}
}
Answer by jj_unity328 · Jul 16, 2018 at 06:49 AM
This, while not perfect either, will allow you to highlight whatever you want.
Source: https://unity3d.college/2017/09/04/customizing-hierarchy-bold-prefab-text/
Note that there is also a link to a youtube video in the link.
Eg taken from the link to highlight prefabs:
using System.Linq;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class CustomHierarchy : MonoBehaviour
{
private static Vector2 offset = new Vector2(0, 2);
static CustomHierarchy()
{
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI;
}
private static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
{
Color fontColor = Color.blue;
Color backgroundColor = new Color(.76f, .76f, .76f);
var obj = EditorUtility.InstanceIDToObject(instanceID);
if (obj != null)
{
var prefabType = PrefabUtility.GetPrefabType(obj);
if (prefabType == PrefabType.PrefabInstance)
{
if (Selection.instanceIDs.Contains(instanceID))
{
fontColor = Color.white;
backgroundColor = new Color(0.24f, 0.48f, 0.90f);
}
Rect offsetRect = new Rect(selectionRect.position + offset, selectionRect.size);
EditorGUI.DrawRect(selectionRect, backgroundColor);
EditorGUI.LabelField(offsetRect, obj.name, new GUIStyle()
{
normal = new GUIStyleState() { textColor = fontColor },
fontStyle = FontStyle.Bold
}
);
}
}
}
}
should i put this script on an empty gameobject in hierarchy ???
@sumit47 It only need to reside in your Project in a Editor folder. It doesn't actually need to be a $$anonymous$$onoBehaviour afaIk.