Instantiating into a Parent Object

Al Heck
2 min readMay 21, 2021

--

Objective: When instantiating, assign gameobject into a parent object for a less cluttered project. Also how do you adjust a instantiated object.

Let’s reduce the clutter. To do this, we need to create a enemy container object under our spawn manager. Then when we instantiate an object, we need to make that instantiated object a child of another object in our hierarchy.

To do this, let’s first define our game object. We can either serialize it or use a find method:

Then under our instantiate code, let’s set the position of our instantiated object. In order to do this, we need to make sure we declare our object that we instantiated as an object that can be reachable. After that, we can easily adjust the clone’s parent attribute position. We can also add a Destroy function to kill each clone after a certain point of time.

Now each instantiated object can be manipulated as well.

--

--

Al Heck

Unity Developer and Software Engineer who loves making games with GameDevHQ