[URP] Fix Shearing and Mesh Distortion when Rotating Scaled Parent Transforms
Solution
Unity 2019.4.x - Unity 6.3.x
Published 12 days ago
When a parent GameObject possesses a non-uniform scale and undergoes rotation, child mesh objects experience skewed deformation or shearing. This occurs because the non-uniform scale creates a non-orthogonal transformation matrix that is inherited by child objects, distorting their local coordinate space as they rotate relative to the parent's axes.
To prevent mesh distortion when parent objects are rotated, it is essential to maintain a uniform scale on all container objects within the hierarchy.
- Identify the parent
GameObjectcausing the distortion by checking itsTransformvalues for any non-uniform scale (e.g., scale values that are not identical across X, Y, and Z). - Reset the parent’s scale to a uniform value, preferably (1, 1, 1), to ensure a clean coordinate system.
- Apply the required non-uniform scale only to leaf nodes, which are
GameObjectinstances that do not contain any children. - For rotational components like turrets or hinges, create an empty
GameObjectto act as a pivot. Ensure this pivot has a scale of (1, 1, 1). - Parent your mesh to this pivot and modify the
Transform.localRotationof the pivot rather than the scaled mesh directly.
Additional Tips
- Bake your non-uniform scale directly into the mesh using external 3D modeling software or ProBuilder before importing to avoid runtime hierarchy issues.
- If you must scale a parent dynamically, ensure all children are unparented before the rotation occurs and reparented afterward, though this is rarely performant.
- Use
Transform.lossyScalein your script if you need to read the global scale of a mesh affected by a non-uniform scale higher in the hierarchy.
TL;DR
Isolate non-uniform scale to leaf nodes and use uniformly scaled Transform pivots to maintain geometric integrity during rotation.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
Content inspired by a Unity discussion post.