Preventing Clutter in the Hierarchy
Organization in Unity’s hierarchy may not be a significant issue early on in a project, however with time numerous loose game objects will make everything more difficult. It’s best to solve this problem in the beginning using the parent and child features in the hierarchy. In this example we will tidy up the enemy spawning by making them children of our spawn manager. First, we create an empty game object under the spawn manager called “enemy container”.
In order to utilize the new enemy container game object, a serialized reference to it in the spawn script is necessary in addition to dragging it from the hierarchy to the component section.
Next we need access to the enemy game objects we are instantiating. In order to use a reference to the game object, we must first store it in into a new game object type variable. Now we can set the parent using our newly created variable and the transform component.