Unity: Scale nuances

This Article covers some Unity’s Scaling nuances I have experienced so far.

But first, here’s a brief explanation of Unity’s gameobject transforms and how they interact with each other.

Unity’s gameobject transforms are parent dependent.

You can make a gameobject a child, by dragging it into the parent gameobject. Then the child will be effected by its parent’s transforms.

Here’s a small example,

Lets’s say there are 3 gameobjects all with the same image called “Object”.

Parent 1 is of scale 0.5 = 50% scale of the image

Child A is of scale 1 = 50% scale of the image

Child B is of scale 0.5 = 25% scale of the image

Unity’s gameobjects, Parent and Children relationships

Keep in mind, that all 3 transforms, the position, rotation, scale are effected this way. Parent dependent.


Now for some nuances…

While working on a game, I noticed the Scale has a certain issue or bug or property or whatever you want to call it.

If you set the scale of an axis to 0. Its children will lock its translation in that axis.

Parent 1 Z=0 and Child A Z=600. But they are at same Z position.

That means the child cannot move in that axis, in which its parent’s scale is set to 0.

The Z position is updated(top right corner) but the gameobject Child A doesn’t move.

In the above example the Z scale of Parent 1 is set to 0. Therefore its Child A is locked in Z position and cannot move in Z axis.

I am not sure, what to call this. Doesn’t feel like a bug, but a functionality of Unity’s Parent Child relationship. Either way, we had a issue show up because of this. We, couldn’t figure out why an animation stopped working after re-parenting a gameobject. We eventually found out one of it’s parent’s Z scale was set to 0. Maybe this could be used an intentional feature to lock some axis from moving? ¯\_(ツ)_/¯

Also, it doesn’t matter if its the immediate parent set to 0. It could be anywhere up the hierarchy chain!

Note that, this a lot harder to do on 3D objects versus 2D objects. Re-parenting a 3D model to a parent whose scale in any axis in set to 0, will make the mesh disappear right away. So, you can visually see something is wrong.


Another nuance…

This is more of a custom solution than a nuance. Since Unity re-parenting is dependent on parent’s transforms. If you re-parent an object then reset the transform, you can move the object back and have the transforms from it’s previous parent. This way you have the transforms/pivots of other objects under other objects. There would be times when we needed custom pivots. Or just move a gameobject inside another gameobject since they need to move together.

We made a Re-parenting script.

This script had the option to move a gameobject from one parent to another when enabled and revert when disabled. We also gave it the option to ignore or adhere to its new or old parent’s transforms.

An example of this would be “If someone brought a box of chocolates and kept it in a car. That car would move carrying the box“. In such a case we would re-parent the Box gameobject from the Character gameobject to the Car gameobject using this script. Then moving the Car would also move the Box.