- Home /
Labeling objects in the scene editor view
I'm working on a scene with a lot of objects that are visually identical but which I need to see the game object name for. I looked at using the OnDrawGizmos() method, but there doesn't seem to be a Gizmos.DrawText or similar. Is there a way to write the object's name next to it in the scene editor view but not in the game?
Answer by yoyo · Jan 27, 2011 at 01:10 AM
See Handles.Label for information on how to draw text in the scene view.
Handles is an Editor class, so you'll need something like this in a script in your Editor folder (C#):
[DrawGizmo(GizmoType.SelectedOrChild | GizmoType.NotSelected)]
static void DrawGameObjectName(Transform transform, GizmoType gizmoType)
{
Handles.Label(transform.position, transform.gameObject.name);
}
Note that this adds a gizmo for every Transform in the scene, so it will show for every game object.
Share the full class, it was difficult to find a post sharing the complete class, since this has to be an editor for Transform or GameObject
Is there a way to search the scene for all objects that are assets with a certain label? I'm trying to search l:Dynamic for objects that have the Dynamic tag but it only finds in the project, not in the scene.
Answer by Dacke · Apr 26, 2016 at 10:37 PM
And for some other color:
GUIStyle style = new GUIStyle();
style.normal.textColor = Color.red;
Handles.Label(transform.position, transform.gameObject.name, style);
Is there a way to search the scene for all objects that are assets with a certain label? I'm trying to search l:Dynamic for objects that have the Dynamic tag but it only finds in the project, not in the scene.