- Home /
Find Objects with particular tag
Hi there I cant find it or it doesnt exist, i would like to see all objects in the hierachy only containing a certain tag, is this possible??
i notice there is a way to see only labels in the project pane but i cant seem to find where and if the tag view is
you would probably want to create a custom editor component I guess.. if it were me, I might consider switching to na$$anonymous$$g conventions as opposed to tags, then everything will all group up automatically by alphabetization (just a suggestion)
Answer by flamy · Aug 06, 2012 at 12:40 PM
well i cannot find a way to show only particular objects in hierarchy but i found a way to see the list of objects in a custom window and select the objects using that window in the hierarchy.
using UnityEngine;
using System.Collections;
using UnityEditor;
public class TagSearcher : EditorWindow {
static TagSearcher window;
static string tagValue="";
static string oldTagValue;
static Vector2 scrollValue=Vector2.zero;
static GameObject[] searchResult;
[MenuItem("EditorUtility/TagSearcher")]
static void OpenTagSearcher()
{
window = (TagSearcher)EditorWindow.GetWindow (typeof (TagSearcher));
searchResult = GameObject.FindGameObjectsWithTag(tagValue);
}
void OnGUI()
{
oldTagValue=tagValue;
tagValue=EditorGUILayout.TagField(tagValue);
if(tagValue != oldTagValue)
{
searchResult = GameObject.FindGameObjectsWithTag(tagValue);
Selection.objects = searchResult;
}
scrollValue=EditorGUILayout.BeginScrollView(scrollValue);
if(searchResult != null)
{
foreach(GameObject obj in searchResult)
{
if(obj !=null)
{
if(GUILayout.Button(obj.name))//,GUIStyle.none))
{
Selection.activeObject = obj;
EditorGUIUtility.PingObject(obj);
}
}
else
{
searchResult = GameObject.FindGameObjectsWithTag(tagValue);
Selection.objects = searchResult;
break;
}
}
}
EditorGUILayout.EndScrollView();
}
}
By default it will select all objects with that tag. but you can select the individual objects also using the window.
nice saves me a lot of time learning and making something like this, to be fair i probably wouldnt of though as unity have improved on how you find stuff, so it might support it.
either way nice work, this is going to be used frequently by me, its nice to be able to check my tags when testing
very good :)
thanks I've learned how could I do my own unity editor modifiers and at last I can see if I have some tags unused so I know what I can delete or rename
so I don't end doing 100 tags and only few usable easier to track all :)
thumbs up :)
heh thought I had some unused ones but now I see I have all used and even know by what :)
This script doesn't work in unity 4.5.2 , it crashes unity. If anyone knows the reason, please modify the script.
Very nice! Saved me a lot of time hunting down tags. $$anonymous$$e like.
Answer by MaT227 · Aug 06, 2012 at 10:58 AM
You can see object by component just by adding :
t:mycomponent in the search field or you can do something like Seth said : http://docs.unity3d.com/Documentation/ScriptReference/Selection-objects.html
Why the downvotes? This is actually a really helpful answer; that link has some good info and actually solves the problem posed by the OP.
Because t: searches objects with components of the a certain type not a objects with the tag. Therefore it will not show for instance the "Player" tag.