Search Unity

Automatically adding child GameObjects to parent GameObject list in editor

Discussion in 'Scripting' started by BobFinery, Oct 24, 2014.

  1. BobFinery

    BobFinery

    Joined:
    Oct 14, 2014
    Posts:
    46
    Hi,

    Currently if I want to have a bunch of objects that I use in game I create a GameObject (with a script that has a list) that I use for a container. I then create the GameObjects and add them as a child.

    I then have to access the parent GameObject list property in the inspector and manually change the list size and drag the child into the corresponding Element.

    Is there an easier way to do this, or am I doing it completely wrong?

    While it isn't too much hassle to do it the way I am it seems a bit cumbersome.

    Cheers,
    Bob
     
  2. BobFinery

    BobFinery

    Joined:
    Oct 14, 2014
    Posts:
    46
    Just to give you an idea as to what I am doing:
    I have a GameObject (called "AI Players" with a script that is simply a list of type CAIPlayer
    I then have a gameobject with a component script of CAIPlayer.

    What I want to do is create a game object for a CAIPlayer, setup its attribults, name, skill or whatever then put that as a child of AI Players.

    Currently when I do that I need to increase the list size in AI Players object and drag the new CAIPlayer GameObject (that is now a child of "AI Players" in the hierarchy view).