x


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??

more ▼

asked Aug 05 '12 at 11:36 PM

reptilebeats gravatar image

reptilebeats
1.2k 57 108 137

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

Aug 05 '12 at 11:37 PM reptilebeats

you would probably want to create a custom editor component I guess.. if it were me, I might consider switching to naming conventions as opposed to tags, then everything will all group up automatically by alphabetization (just a suggestion)

Aug 06 '12 at 07:08 AM Seth Bergman
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Aug 06 '12 at 12:40 PM

flamy gravatar image

flamy
3.6k 5 12 38

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

Aug 06 '12 at 03:41 PM reptilebeats

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 :)

Mar 17 at 05:32 AM sdgd
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Aug 06 '12 at 10:58 AM

MaT. gravatar image

MaT.
173 7 11 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3893
x1732
x175
x151
x145

asked: Aug 05 '12 at 11:36 PM

Seen: 389 times

Last Updated: Apr 10 at 08:32 AM