Find objects that only transforms as component and nothing else

Hey guys,

How would you go about finding objects in the scene that only have a transform component attached to it? it’s important that they don’t have anything else.

I want to know this because I want to script a scene cleaner, the idea would be to remove all parent objects that no longer have children.

Thanks for your help! ;D

Try this.

var components = go.GetComponents<Component>();
if(components.Length==1)
{
    // Has only a transform
}

Smart! Thanks, it worked :wink: