1
\$\begingroup\$

So I have a GameObject which my scene will be it's children.
I wanted to get the BoxCollider of all the objects and their sub-objects and their sub-objects's sub-objects and ... .
So can I do that with just the GetComponentsInChildren(), or should I navigate through them all and find them one by one?

\$\endgroup\$
  • \$\begingroup\$ You provide a link to official documetation that clearly states you can, why did you think you could not? \$\endgroup\$ – Gnemlock Jan 14 '17 at 5:59
2
\$\begingroup\$

The documentation you link covers the answer to this, quite clearly. GetComponentsInChildren will return components from all sub children.


This is the API reference you link, emphasis mine:

Description
Returns all components of Type type in the GameObject or any of its children.

The search for components is carried out recursively on child objects, so it includes children of children, and so on.
- Unity API: GameObject. GetComponentsInChildren

\$\endgroup\$
  • \$\begingroup\$ Sorry, I tested it and it wasn't clear if it worked properly so I asked to make sure of that, and thank you \$\endgroup\$ – Henjin Jan 14 '17 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.