How do I check if an object is empty

How do I check if an object is empty? As in I have added it by going GameObject -> Create Empty

Basicly I did this to group a bunch of objects together, and gave it a tag, so I could search for the tag via FindGameObjectsWithTag, then iterate the children if it was empty).

try this:

if(gameObject.transform.childCount == 0) //empty

then you can iterate its children via this:

for( int i=0; i<gameObject.transform.childCount; i++ )
	GameObject go = gameObject.transform.GetChild(i).gameObject;

An object is empty if it doesn’t have any components besides the Transform attached to it. Regardless of what it is (A MonoBehaviour (script), or a MeshFilter, or a RigidBody, etc. etc.) they all have in common that they inherit from Component. This means that if you call GetComponents and then supply “Component” as the argument, then you’ll get an array containing every single component attached to that gameobject, because due to the inheritance, they are ALL ultimately of type Component.

If this array’s length is only 1, then it means the only component attached to that gameobject is the mandatory Transform. And then it matches the gameobject you’ll get from choosing GameObject → Create Empty:

    GameObject someGO = GameObject.Find("GameObject");

    Component[] allComponents = someGO.GetComponents<Component>();

    if (allComponents.Length == 1) // Contains only Transform?
        Debug.Log("That gameobject is empty");