|
What is the best way to iterate over all scene objects from an editor script? Supose I want to make a script extract some scene information. Is this the best way?
Could GameObject.FindSceneObjectsOfType pick objects from other editors or other objects that are not in the current scene graph?
(comments are locked)
|
|
That should work fine. In contrast to what you might expect, Unity has no "root node" which you can ask for its children. You have to do what you do now.
(comments are locked)
|
|
And what must I do if I want to get ALL the objects of a given type, not only the ACTIVE ones? Don't ask a question as an answer (this isn't a forum). You'd want to use FindObjectsOfType() here: http://unity3d.com/support/documentation/ScriptReference/Object.FindObjectsOfType.html?from=GameObject
May 13 '10 at 10:10 PM
qJake
that won't return any inactive objects, which is what he's asking. I'd like to now that too :s
Jun 02 '12 at 06:25 PM
Steven 1
Resources.FindObjectsOfTypeAll
Dec 13 '12 at 01:24 AM
invadererik
(comments are locked)
|
|
GameObject doesn't actually contain a definition for FindSceneObjectsOfType(). You'll want to use
instead. For all GameObjects it's just
(comments are locked)
|
|
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.
(comments are locked)
|

You can also just use "foreach (GameObject g in obj)" -- this will effectively perform the typecast for you, and throw an exception if it encounters an object that isn't a GameObject.