# what is the math behind the parenting a transform in unity?

in unity when you parent an object or transform with another object, all transform(position, rotation, scale) are calculated depending on that parent object. sometimes we need to know about the local data of that transform and sometimes we need to know that data based on the world axis.

I need to know how that is implemented in math and vector functions.

• Are you looking for the matrix inverse, to convert from world positions to parent-local positions/etc? What specific operations do you need help implementing? Note that much of this is visible in Unity's published C# code, if you want to see how it implements a specific vector method. Mar 30, 2021 at 11:52
• @DMGregory really? unity has published implementation of its math and vector classes? i think there is only a basic class for working with unity entities. all I need to know is when parent object updates any of its transforms how child object updates them and how functions like transform.transformpoint and transform.transformdirection work. Mar 30, 2021 at 12:26
• When setting an object as a child, what you essentially do behind the scenes is that you apply the local transformation of the child then apply the local transformation of the parent which yields the resulting world transform. Is that what you were looking for? Mar 30, 2021 at 12:43
• You may be interested in past Q&A like matrices and nesting hierarchy with game objects / Math behind drawing one game object relative to another / Dealing with more complex entities in an ECS architecture (really about parenting) Mar 30, 2021 at 13:48

Parenting an object essentially means that the object's transform now is relative to the parent's instead of the world's. If the parent object is a body for example and the child object is the arm, then the body's position in the world is defined by its bodyTransform and is relative to the world coordinates but the armTransform is relative to the body's space, which I believe is done via a change of basis on the arm object where the new basis is the body's local basis. This means that you can individually change the arm's position by changing its transform relative to the body (which is what you care about) but if the whole body moves, the arm moves with it since its armToWorld transform already contains the bodyTransform inside.