Search Unity

You have a long list of (Clone) game objects in your Hierarchy tab view. Any way to organize them?

Discussion in 'Scripting' started by asperatology, Nov 28, 2015.

  1. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    During runtime, I would be Instantiating() a lot of game objects throughout the duration of the game. Let's assume that I have 200 (Clone) game objects.

    How do you organize them in the Hierarchy tab in Unity editor? Or it is recommended to be lazy and just let it tack itself to the bottom-most space of the Hierarchy tab?

    And is it possible to obtain all of the (Clone) game objects if they are organized?
     
    Last edited: Nov 28, 2015
  2. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I normally create a top level parent game object and create the clones as children. This allows you to fold them up and even put them in categories.
     
    Kiwasi likes this.
  3. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    There's an InstantiateToChildren() or similar function?
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Not directly, but you can always call Transform.SetParent. If this really bothers you then you can always wrap it in your own function call.
     
  5. apsdsm

    apsdsm

    Joined:
    Sep 26, 2013
    Posts:
    56
    I would just add that if you parent the objects to anything, make sure it's actually fulfilling some kind of purpose - for example, they are actually conceptual children of whatever you're parenting them to, or because you want to delete them all at once by killing the parent. Otherwise you're just parenting for the sake of managing the appearance of the editor during runtime, which would be adding complexity to your program for something that, all things considered, doesn't really matter all that much.

    To answer the second part of your question, you can iterate through all the clone objects at once if they're parented to the one object. That's a simple:

    Code (CSharp):
    1. foreach ( Transform child in transform ) { }
    on the parent object.
     
  6. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Easiest way is to do something like this
    Go = instantiate(whatever)
    Go.transform.parent = parentgameobject.transform;
     
    Kiwasi likes this.