e.g. if I have a tag “Player”, how to search all game objects filtering with the tag “Player”?
I know how to write the script to achieve what I want, but I do not know to operate in unity editor
I don’t think you can do it out of the box. Check the Asset Store.
If you’re up to the task, you could try to learn how to code your own Editor script that does it.
An Introduction to Editor Scripting (official guide by Unity)
Unity Editor Scripting - Filtering Hierarchy by Tag or Layer (nevzatarman’s blog)
For anyone reading this in the future, Unity now has a Quick Search package which does wonders in terms of search within prefabs, scenes, hierarchies, project files - you name it! And it support editing thousands of objects at the same time! Here is the cheat sheet with all filters: The Great QuickSearch Syntax Cheat Sheet | Quick Search | 2.1.0-preview.5
I have come a long way to leave you the treasure of the ancestors. If you are looking for how to find an object with some tag in a project, you can use this script. Put it in the Editor folder.
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
public class TagToolsWindow : EditorWindow
{
private static string Tag;
private static bool IncludeInactive = true;
[MenuItem("Tools/Tag find window")]
static void Init()
{
// Get existing open window or if none, make a new one:
TagToolsWindow window = (TagToolsWindow)EditorWindow.GetWindow(typeof(TagToolsWindow));
window.Show();
}
private void OnGUI()
{
Tag = EditorGUILayout.TextField("Search Tag", Tag);
IncludeInactive = EditorGUILayout.Toggle("Include inactive", IncludeInactive);
if (GUILayout.Button("Find In Assets"))
{
FindTagInAssets();
}
if (GUILayout.Button("Find In Scenes"))
{
FindTagInSceneObjects();
}
}
private void FindTagInAssets()
{
var guids = AssetDatabase.FindAssets("t:GameObject");
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var asset = AssetDatabase.LoadAssetAtPath<GameObject>(path);
if (asset)
{
var gameObjects = asset.GetComponents<Transform>();
foreach (var gameObject in gameObjects)
{
if (gameObject.tag.Equals(Tag))
{
Debug.Log($"Find Asset {asset.name} GameObject {gameObject.name} with {Tag} tag in path:{path}", asset);
}
}
}
}
}
private void FindTagInSceneObjects()
{
var guids = AssetDatabase.FindAssets("t:Scene");
foreach (var guid in guids)
{
var path = AssetDatabase.GUIDToAssetPath(guid);
var scene = EditorSceneManager.GetSceneByPath(path);
EditorSceneManager.OpenScene(path);
var sceneGameObjects = FindObjectsOfType<GameObject>(IncludeInactive);
foreach (var sceneGameObject in sceneGameObjects)
{
if (sceneGameObject.tag.Equals(Tag))
{
Debug.Log($"Find Scene gameObject {sceneGameObject.name} with {Tag} tag in scene:{path}");
}
}
}
}
}