When you instantiate a game object into a scene within unity it will appear as a new object within the hierarchy. This can prove to be annoying as new objects continue to spawn and clutter up the window…
So what should I do?
It’s easy! The simplest way to go about correcting this is to create an empty game object in the hierarchy and use it as a storage container from which to assign all newly instantiated objects as children. The code below shows how to implement this.
You will need to drag and drop the prefab you are wanting to spawn into the game object reference “_enemy” within the hierarchy. The empty game object that will be used as a storage container will need to be referenced as well. Drag and drop that object into the game object reference _enemyContainer within the hierarchy.