How to find out to which GameObjects a certain Script is applied?

It is easy to see which Scripts are assigned to a specific GameObject, but not vice-versa:

which GameObjects are connected to a certain Script. So I want to click on the Script and see which GameObjects or prefabs are using it.

The only way I found so far is to browse all GameObjects and its parts to see what Scripts are attached. But if there are multiple and/or complex Objects in the Scene it becomes very hard.

Same question with the public variables overrides from the Unity. Maybe there is any indication that something like this was done in Unity and I missed it?

Thanks in advance!

One thing you can do is use the search field in the Hierarchy view. If you enter the full name of the script/component, only objects containing it will be listed in the view. It would be nice if this worked in the Project view too, but it does not, so you’ll have to do it scene by scene.

In Unity 5 just right click on a script and click “Find References In Scene”. It will add the search term to the search bar in the Hierarchy view. Just clear this string to see all the scenes game objects again.

I haven’t tried it, personally, but the Unify wiki offers this SelectByComponent script. If that doesn’t work, you could try using something based on the SceneDumper script.

If I had to do it from scratch, I’d probably start by calling Object.FindObjectsOfType(), and then iterating over the returned list. That looks like about what the SelectByComponent script is doing, at a glance.

Easy just add this in your scripts start method

print ("I’m Attached to " + this.gameObject);

you can put break point in the script’s awake or start function and then in the watch window see the value of " this. gameObject"

Thank God, you saved me a bunch of researching. I had created a cube, and thought I named it, and added a script to it, but, as it turns out, the cube never got the name, and I had already made it NOT ACTIVE, so doing this RIGHT CLICK ON THE SCRIPT and FIND REFERENCES worked “PERFECTLY”. THANKS MUCH

If you drag all scenes in the projectview then you can find the references of a script in all the scenes that are dragged in the projectview panel!

in the script you looking for write in start void debug,log(“Im Here lol”, gameObject); then start the game and watch console

Had the same problem, found easy solution @Khrys.

  1. Open your script in Visual Studio

  2. On the beginning of your script you should have sth like
    using UnityEngine;

    public class MyScript
    {

  3. Above this public you should have info how many times your script is used in Unity, if you click on this info it should list all items it is attached to.