Reputation:
I have a game in Unity where I instantiate GameObjects every few seconds. Then in the Hierarchy, the prefabs show up in a list of them being instantiated e.g.:
EnemyBlue(Clone)
EnemyRed(Clone)
EnemyGreen(Clone)
EnemyBlue(Clone)
Which clogs up my hierarchy. My question is, is it possible to instantiate GameObjects as a child of an empty GameObject, for example:
Enemies // An Empty GameObject
EnemyBlue(Clone)
EnemyRed(Clone)
EnemyGreen(Clone)
EnemyBlue(Clone)
Upvotes: 4
Views: 305
Reputation: 2472
You can set the parent of a transform like ILiveForVR mentioned, but you can also set the parent for something that already exists:
gameObject.transform.parent = GameObject.Find("Name of game object").transform;
Upvotes: 4
Reputation: 1043
You can set the parent of an object after you instantiate it: http://docs.unity3d.com/ScriptReference/Transform.SetParent.html
So something like:EnemyBlue.tranform.SetParent(Enemies.transform);
Upvotes: 2