Checking If Unity GameObject Has Child Object

In Unity we use the childCount property to check if a GameObject has a child object or objects.

If this value is greater than 0 it has at least 1 child object.

An example of its use is given below..

GameObject go = GameObject.Find("TestGameObject"); if (go.transform.childCount > 0) { //Child object exists } else { //Child object NOT exists }

In our example, we found whether our GameObject variable named "go" has "childCount" property and its "child" object or objects.



You May Interest

Using Unity Editor Black Theme

Using the Unity Editor Device Simulator

Searching Multiple GameObjects By Unity Tag

What is Unity Asset?

What is Unity MonoDevelop ?