- Home /
Accessing Child GameObject
I know there must be a simple solution to this, but I can't seem to figure it out. I have an object attached to an NPC, and I want to access it so as to enable and disable it through the script on the parent. How do I go about this?
If it is an immediate child, or if you know the path from the parent to the child, you can use Transform.Find().
This is a possible duplicate of this question: http://answers.unity3d.com/questions/10417/how-can-i-access-the-children-of-a-transform.html There's a pretty good answer there, see if it works for you :)
Answer by Sundar · Nov 28, 2013 at 03:39 AM
Try this
Transform aChild = transform.FindChild( "child name" );
if( aChild != null )
{
Debug.Log( "Found child" );
aChild.gameobject.SetActive( true ); // false
}
else Debug.Log( "Child not found" );
Attach it to the parent
Your answer
![](https://koobas.hobune.stream/wayback/20220613122957im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Make a simple tree 1 Answer
How can I access the children of a Transform? 5 Answers
Change the color of a child 1 Answer
Help with local/world positiong a new gameobject 1 Answer
rapid movement back and forth 1 Answer