- Home /
GameObject's scale gets 0 after being parented in editor
1) Before
2) After being parented.
Update1: Okay so I found a pattern. When adding the child, if the parent's scale.z = 0 the child scale.xyz becomes 0 on parenting. If the parent's scale.z != 0 it works. Another experiment that I tried was, after successfully adding the child(without getting scaled down to 0) and then to make the parent's scale.z = 0, the children's scales don't get affected at all.
Why?
So, you solved it. Don't have any parent scale be zero. In general, I can't think of a reason to ever have a scale set to zero. Usually the parents are kept as (1,1,1) empties.
Not sure if this is a bug -- I think it's just how the math works out, for children.
Yeah, there are always problems, in my experience, with parenting an object to a non-uniform scale transform. Try to avoid it at all costs.
Answer by MapuHoB · May 19, 2015 at 07:14 AM
When you change an object's parent in Unity, the editor automatically adjusts the object's local position/rotation/scale values so that the global appearance stays the same (or as close as possible)
So for instance, if I take an object with scale (1, 1, 1), and add it to a parent with scale (2, 2, 2), Unity will adjust the child's scale to (0.5, 0.5, 0.5) so that the net result of its transform hierarchy is the same (1, 1, 1) it started with.
Unfortunately, there are a few cases where this breaks down, and Unity can't maintain the object's global appearance. One such case is if any of the parent's scale axes are zero. Trying to compensate for a zero scale results in a division by zero, so there's no right answer.
It looks like in this case, Unity sets the scale of the object to zero as a fallback.
The best way to avoid this complication is to not use non-uniform scaling on parent objects. Uniformly scaled transforms are easy to nest & re-parent without loss or distortion.
Your answer
Follow this Question
Related Questions
Game Object Scaling based on Proximity 1 Answer
How to get an object to fill 3/4th of the screen. 0 Answers
Match a GameObject's size to another's? 2 Answers
Make gameobject size always be the same 3 Answers