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
3
Question by Reaksmey-Rt · Dec 10, 2014 at 04:24 AM · find-gameobject

How Can I find object Child's Child or Child in child with name ?

Dear Sir/Madam

**How Can I find object Child's Child or Child in child with name ?**please see the picture.

alt text

child's child.png (16.2 kB)
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

5 Replies

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

Answer by Bunny83 · Dec 10, 2014 at 04:26 AM

http://docs.unity3d.com/ScriptReference/Transform.Find.html

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
3

Answer by Kiour_gr · Sep 22, 2020 at 07:01 AM

I know this post is ancient, but when I had the same problem this link came up on Google so chill. From what I read still in 2020 there is no way to search by name all of the children's children bellow the parent.

What I did was make a static function to do the above for me. I am replying to an ancient post cause maybe someone else finds it useful.

 public static GameObject descendant = null;
 
 public static GameObject ReturnDecendantOfParent(GameObject parent, string descendantName)
     {
      
             foreach (Transform child in parent.transform)
             {                   
                 if (child.name == descendantName)
                { 
                 descendant = child.gameObject;                 
                 break;
                 }
                 else
                 {
                     ReturnDecendantOfParent(child.gameObject, descendantName);
                 }                  
             }
         return descendant;
     }
 
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 KarlKarl2000 · Mar 17, 2018 at 10:28 PM

@ Reaksmey-Rt transform.Find is a god send. [Edit] Read Bunny's useful top link for more clarification on use.

@ Janibasha had a brute force way to code it, which I used to use. But I found another way that I like better.

If we assume Hero1 is the top most game object. Also we assume your script is on Hero1.

    public GameObject _hero1; //assuming these are gameobjects
    public GameObject _use; //assuming these are gameobjects

    Void Start ()
    {
        _use = _hero1.transform.Find("Information").transform.Find("Use").gameobject;
    }

Hope this helps others that find this thread.

sharin' is carin'

@indieDoroid

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 · Mar 17, 2018 at 10:43 PM 0
Share

This is what i answered 3 years ago. Also if you actually read the documentation page i've linked in my answer you will notice that you can use a "path-like" string. So you can simply do:

 _use = _hero1.transform.Find("Information/Use").gameobject;

The documentation does mention this in the description and actually has a code example as well.


However i don't think the OP cares anymore since he wasn't seen here since nov. 2016 and this question is already 3+ years old.

avatar image KarlKarl2000 Bunny83 · Mar 18, 2018 at 09:40 PM 0
Share

Ooooh even better solution. I missed that part in the documentation. $$anonymous$$uch shorter and sweeter!

Yea its an old thread, but even after 3 years your response was helpful for me. So thanks again for your contributions to the Unity forums!

avatar image
0

Answer by Janibasha · Aug 09, 2017 at 09:02 AM

First Get the game object Hero1 like below

Gameobject hero1 = GameObject.Find("Hero1");

then

Transform Cancel = Hero1.transform.GetChild(0); if u want Use chnge index as 1

Cancel .transform.GetChild(0).gameObject.GetComponent().color = new Color(126, 80, 80, 255);

thats it...

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 ShadyProductions · Aug 09, 2017 at 09:05 AM -1
Share

Don't wake up old posts, this was already answered.

avatar image Janibasha ShadyProductions · Sep 26, 2017 at 03:05 PM 0
Share

a clear ans..

avatar image
0

Answer by wopkatan · Oct 17, 2018 at 06:30 AM

for me that did the trick:

 GetComponentInChildren<>()

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

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

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

Instantiate problems 1 Answer

Find All FindObjectOfType() 1 Answer

How do I find all game objects with the same name? 7 Answers

How do I find a child object in a hierarchy of children? 1 Answer

Code for built-in Find() function? 1 Answer


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