Quickly isolate GameObjects in Hierarchy with scripts in them?

In the Unity IDE: Is there a way to quickly find out which GameObjects in Hierarchy have scripts attached? Is there a way to find out which scripts are attached to which objects?

Not sure when this feature was added, but now there is a built-in solution.

Simply type the FULL NAME of the component you’re looking for into the hierarchy search box and it will highlight all objects with that component.

typing “anim” will only come up with gameObjects with “anim” in the name.

typing “animation” will come up with all gameObjects with “animation” components attached.

Add this script to your Assets\Editor folder and you will get a menu item that dumps information about the scene to a text file, including which components (scripts) are attached to which objects.

It basically implements Justin's suggestion.

You could modify the script to be more fully integrated with the IDE. Reverse lookup would be a cool feature -- i.e. "select all game objects using this script." Hmm, useful enough that maybe I'll go implement it ...

OK, so I got a little carried away, but see http://zeroandone.ca/unity for a package that implements this and other features. Here's a screenshot (click here for full size image) ...

alt text

You can grab the package and look at the source code, or just use it. The implementation does roughly this ...

  • select your script in the Project view (identified as Selection.objects from an editor script)
  • get this as a MonoScript object representing the script asset
  • use MonoScript.GetClass to determine the component type (returns null for scripts that don't implement MonoBehaviour)
  • search all the root objects of the scene (transform.parent == null) and their descendants for use of the component type, with GameObject.GetComponentsInChildren
  • select the found objects by setting Selection.objects
  • Debug.Log as well, with a game object context parameter for handy highlighting