- Home /
How do I find a gameobject inside another gameObject without knowing the name of the child
It may seem like I didn't look, but I went through quite a few "forms" and found nothing. I need to find the child inside of a parent that I know the name of but, not the child's name because the child is always changing. So I can't have the name of the child, and if I did know the name of the child I wouldn't be here.
Answer by kirbygc00 · Apr 11, 2020 at 08:21 PM
if you know the type some component on the child you can use
GetComponentInChildren
https://docs.unity3d.com/ScriptReference/Component.GetComponentInChildren.htmlif you have tagged the prefab with a specific tag you can use
FindWithTag
https://docs.unity3d.com/ScriptReference/GameObject.FindGameObjectsWithTag.html
I would stick with the first approach if possible. it will sort through the entire hierarchy for that object and find the gameobject with the specified script/component
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers