- Home /
Find GameObject of tag "x" no matter where it is?
Good evening,
I need to find a GameObject with the tag "TargetMatch", but for some reason it isn't as simple as:
'GameObject.FindGameObjectWithTag("TargetMatch");'
Because it only finds parent GameObjects, and doesn't find childs of a GameObject which have the tag "TargetMatch".
Can someone help me how I can find parent AND child GameObjects?
I hope you understand my question.
Thank you! :3
Answer by Sisso · Jun 07, 2013 at 07:29 PM
If I understand correctly, your assumption "Because it only finds parent GameObjects, and doesn't find childs of a GameObject which have the tag" is wrong. It search in all active scene objects.
http://docs.unity3d.com/Documentation/ScriptReference/GameObject.FindWithTag.html
Probably, the problem is in another place.
Answer by tyjkenn · Jun 07, 2013 at 07:39 PM
Make sure all the child objects are marked with the tag, not just the parent object. Also, you should use GameObject.FindGameObjectsWithTag("TargetMatch")
in order to get all the objects with the tag and not just the first one it finds.
Your answer
![](https://koobas.hobune.stream/wayback/20220613103720im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Find Script in parent Gameobject? 3 Answers
Using parent tag on whole gameObject 1 Answer
(C#) How do I run something in my child's script? 2 Answers
Change gameObjects parent at runtime 3 Answers
Help to get access to the parent 2 Answers