Don’t Forget Position when Creating Collection Parent Objects

by Lance Gold

To avoid a seeming dynamic placement of objects, set the Parent’s location as well as the children’s locations.

Return to index

Here is the starting point with a single laser child with not parent.

single laser shot

single laser shot

The child laser object has a Transform position of (x,y,z): (0,0,0).

After the drag and drop from Prefabs to the Hierarchy, and a duplication (press ctrl-D), and a repositioning (rect. tool) to originate three lasers from the three corners of the Player ship, we have this triple laser shot:

Layout for three laser shot

Layout for three laser shot

The Position for the three lasers are 1, 2, 3: (-0.8, -0.25, 0) (0, 1, 0), (0.8, -0.25, 0).

After creating an empty object named “Triple_Shot” to be the container and parent of the three children laser objects, notice the Parent’s location assigned by Unity:

New empty object with Unity assigned location

New empty object with Unity assigned location

Unity set an unaltered location of about (0.05, 0.19, -3.51)

Drag the children into the parent.

Drag children lasers into Parent Triple_Shot

Drag children lasers into Parent Triple_Shot

The error in location, visible after dragging Triple_Shot to Prefabs, deleting the prehighlighting Player in Hierarchy, draging Triple_Shot Prefab to the Player (Script) component (and creating the GameObject variable in the C# script):

Player (Script) with Triple Shot Prefab assigned

Player (Script) with Triple Shot Prefab assigned

Before resetting the parent Transform location:

Laser Parent location before position correction

Laser Parent location before position correction

Delete the error and recreate. When the empty object is created, set the Position of Triple_Shot to (0, 0, 0) before dragging to the Prefabs folder.

Here is the correct firing location from the Player ship after setting (0, 0, 0):

Create empty and corrected Position with zeros

Create empty and corrected Position with zeros

Here is the visual:

Corrected firing visual

Corrected firing visual