Hello guys!
Just wanted to share a very small tool I created for the Unity editor, it allows you to find game objects in the hierarchy by tag, very simple yet effective.
Hope you guys find it useful.
Here's the code. For it to work you need to put it inside a folder named 'Editor'.
using UnityEngine;
using UnityEditor;
namespace Yee.Tools
{
public class FinderByTag : EditorWindow
{
[MenuItem("Find/Find by Tag")]
static void Init()
{
FinderByTag window = ScriptableObject.CreateInstance<FinderByTag>();
float height = UnityEditorInternal.InternalEditorUtility.tags.Length * 21;
window.position = new Rect(Screen.width / 2, Screen.height / 2 - height / 2, 250, height);
window.ShowPopup();
}
void OnGUI()
{
foreach (string tag in UnityEditorInternal.InternalEditorUtility.tags)
{
if (GUILayout.Button(tag))
{
GameObject objectWithTag = GameObject.FindGameObjectWithTag(tag);
if (objectWithTag != null)
{
Debug.Log(objectWithTag);
Selection.activeGameObject = objectWithTag;
}
else { Debug.Log($"No Game Objects with the tag: {tag}, were found in the hierarchy"); }
Close();
}
}
}
}
}
There are some things that can be done to improve this, like being able to move the window around and have a close button instead so you can search for any game object without the window closing. I’ll make those updates later, but as it is, the tool works fine, feel free to use it.