Thank you because that helping us boost the quality of unit Documentation. Although us cannot expropriate all submissions, we do read each suggested readjust from ours users and also will do updates whereby applicable.

You are watching: Unity find child by name


Submission failed

For some factor your suggested readjust could no be submitted. Please shot again in a couple of minutes. And also thank you for taking the moment to assist us enhance the quality of unified Documentation.


If no child with n can be found, null is returned.If n consists of a "/" character it will accessibility the transform in the power structure like a course name.Note: discover does not execute a recursive descend under a change hierarchy.

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour public GameObject player; windy GameObject gun; public change ammo; //Invoked once a switch is clicked. Windy void Example() //Finds and also assigns the boy of the player named "Gun". Total = player.transform.Find("Gun").gameObject; //If the kid was found. If (gun != null) //Find the child called "ammo" of the gameobject "magazine" (magazine is a son of "gun"). Ammo = gun.transform.Find("magazine/ammo"); else Debug.Log("No son with the name "Gun" attached to the player");
As explained Find does not descend the change heirarchy. Uncover will just search the offered list of youngsters looking because that a called Transform. The following instance shows the result of find searching because that GameObjects. The name of every GameObject is provided in the Find. This is why 2 GameObjects in the very same level that the power structure are found and also reported.

A GameObject with 3 children. Find() does not uncover the third child.

See more: Surface Rt Type Cover - Cases, Covers And Keyboard Folios For Surface Rt

// ExampleClass has a GameObject with three spheres attached.// two of this are children of the GameObject. The third// transform, sphere3, is a child of sphere2. Find() does// not uncover this child.using UnityEngine;public course ExampleClass : MonoBehaviour void Start() transform result; for (int i = 1; ns sph = "sphere" + i.ToString(); an outcome = gameObject.transform.Find(sph); if (result) Debug.Log("Found: " + sph); else Debug.Log("Did no find: " + sph); }
Is something explained here not working as you suppose it to? It can be a recognized Issue. Please check with the concern Tracker in ~