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
0
Question by Tabu · Aug 03, 2010 at 05:06 PM · getcomponentgetcomponentinchildren

GetComponentInChildren, is there an Alternative way?

I am looking for a way to find a script, that is positioned under the same GameObject, but not in the same hierarchy. Since there is more GameObjects with the same name and the same Script, "find" is not a possibility. I have been looking through the documentation for a sollution, but haven't been able to find anything..My apologies if there is something after all. My glasses might need cleaning ;)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by qJake · Aug 03, 2010 at 05:24 PM

Uh... are you looking for Object.FindObjectOfType? This returns the first instance of whatever component you give it, but be warned, it is slower than GetComponent and friends!

Edit: If you want to find a child component in a different game object, you first need to get its reference. See this post for how to access other game objects and obtain their references:

http://unity3d.com/support/documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

After you have a "GameObject" object, you can just call myObject.GetComponentInChildren() to get the component reference in that particular game object.

Comment
Add comment · Show 3 · 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 Tabu · Aug 03, 2010 at 07:58 PM 0
Share

If I understand FindObjectsOfType Correctly, this will just find a object in the Scene, and not only under the gameobject that I specify?

avatar image qJake · Aug 04, 2010 at 02:52 AM 0
Share

Oh, you want it under another object? Hang on I'll edit my post, since your question was unclear.

avatar image Tabu · Aug 05, 2010 at 06:53 AM 0
Share

Thank you :) Its a way of solving my problem, but not excatly ;) I'm pretty sure by now that there is no easy way for me to solve this. Let me try to explain a bit better. I have my main GameObject, under this I have two sets of Child hiracies. I want a script in one child hieracy to access a script in the other child hieracy.

Right now I use a script in the main GameObject to access both child scripts, and then pass information through that script.. but I really wanted to access the scripts directly. I am an artist, and started sparetime coding a few months ago, so Im pretty green still :)

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

No one has followed this question yet.

Related Questions

How to get Component from Game Object in C# 1 Answer

What's the most efficient way to change script from child object 2 Answers

transform.root and empty root game objects don't play nice 1 Answer

how do I change the properties of a material that are on the children of an object on script? 1 Answer

GetComponent in parent question 3 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