Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
4
Question by Khrys · Mar 06, 2012 at 11:30 PM · gameobjectconnection

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

9 Replies

· Add your reply
  • Sort: 
avatar image
23

Answer by Steven-Walker · Mar 07, 2012 at 01:48 AM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Khrys · Mar 08, 2012 at 12:16 AM 0
Share

Steven Walker, what version of Unit do you use? I tried to search in the Hierarchy and it doesn't work at all in Unity 3.4 Thanks for your answer.

rutter, it looks like there is no other way. Thanks for the answer.

avatar image Steven-Walker · Mar 08, 2012 at 01:45 AM 0
Share

Be sure you enter the component name exactly and fully without spaces. For example, you would type "$$anonymous$$eshRenderer" to list only objects with a $$anonymous$$esh Renderer component. I'm using Unity 3.5, but I've used this feature for quite a while before that.

avatar image JoeStrout · Oct 25, 2013 at 01:45 AM 1
Share

I've just confirmed that this works fine for me in 4.2.1. It looks like it's not working, because the list narrows down to nothingness as you type, but when you type the last character, scripts with that exact component miraculously reappear.

avatar image Vargas · Jan 06, 2014 at 01:05 AM 1
Share

It works only for the objects currently in the hieracrchy, but not for prefabs =/

avatar image
16

Answer by QBob · May 22, 2015 at 12:08 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by rutter · Mar 07, 2012 at 01:25 AM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by aemason · May 09, 2012 at 08:58 PM

Easy just add this in your scripts start method

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jul 25, 2012 at 12:08 AM 2
Share

That was what i thought at a first glance, but read the question carefully. He wants all gameobjects that have a certain component attached, so FindObjectsOfType is the best solution.

avatar image aemason · Jul 25, 2012 at 01:34 AM 0
Share

Looks like he's asking to see all game objects a certain script is attached to. Every game object that is in a scene would be listed in the console using this line of code. You can do the exact same thing easily with FindObjectsOfType(), iterate through and print names of game objects.

avatar image
0

Answer by dwitee · Sep 30, 2014 at 07:27 AM

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"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Cloned Prefab 3 Answers

How to check connection? 1 Answer

Create customized prefab at runtime and save it 1 Answer

Cannot destroy objects 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges