UnityRef is currently in early development. Some features may be incomplete and/or not functioning.

UNITYREF

Your Pit Stop For Solving ANYTHING in Unity

architecture

[URP] Fix Shearing and Mesh Distortion when Rotating Scaled Parent Transforms

Solution

transformhierarchygeometrymeshscene management

Unity 2019.4.x - Unity 6.3.x

Published 12 days ago

Issue

 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.

Explanation

To prevent mesh distortion when parent objects are rotated, it is essential to maintain a uniform scale on all container objects within the hierarchy.

  1. Identify the parent GameObject causing the distortion by checking its Transform values for any non-uniform scale (e.g., scale values that are not identical across X, Y, and Z).
  2. Reset the parent’s scale to a uniform value, preferably (1, 1, 1), to ensure a clean coordinate system.
  3. Apply the required non-uniform scale only to leaf nodes, which are GameObject instances that do not contain any children.
  4. For rotational components like turrets or hinges, create an empty GameObject to act as a pivot. Ensure this pivot has a scale of (1, 1, 1).
  5. Parent your mesh to this pivot and modify the Transform.localRotation of 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.lossyScale in 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.