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

What is Unity IL2CPP ?

Searching Multiple GameObjects By Unity Tag

GameObject Search By Unity Tag

Adding a Button Property to an Object in Code in Unity

Unity Exit Example