Thanks a lot, this was useful for my own purposes of just operating on the root nodes of my scene. Since nobody else has said it, usually you never want to iterate over every object in your game. Aside from that I wanted to point out two changes i would make to this solution: 1) You're going to need to put "using UnityEngine.SceneManagement;" at the top of your script to use the "Scene" and "SceneManager" keywords. Or just do what I'm doing until I have time to do a full QA cycle, and prepend the entire namespace to each part that needs it. [See code below]

2) If you read on Unity's documentation, they mention that scene.GetRootGameObjects( rootObjects ); should have "rootObjects" already initialized to larger than "scene.rootCount". So I moved the lines around a bit to get the scene and find it's root object count. I don't know how much of an impact it makes especially if you're doing it one time but if you'd like to research further on the effects of Unity "allocating memory internally" vs the List declaration allocating memory on its own, it may or may not be significant. I'm doing it this way to follow the documentation's suggestions. Who knows how up to date it actually is.

The SceneDumper script on the wiki will iterate all the the selected objects and their children. Currently it just prints the object hierarchy and the names of each object's components, but it could be modified to print all the component properties, filter by type, etc.

Given a game object, you can find its top-most ancestor in the scene tree using Transform.root -- i.e. gameobj.transform.root.gameObject. But note that there can be multiple "root" nodes in a scene.