In a transform hierarchy, why does a child object store a transform relative to its parent instead of its world transform?
answer
- derived, not stored
- one write moves a whole subtree
- parent's world composed with child's local
- re-parenting must preserve the world pose
basics
~20 sStoring a local transform lets a child follow its parent automatically: its world transform is the parent's world transform composed with its local one, so moving a vehicle carries the seated character and the weapon in its hand along.
solid answer
~50 sA transform hierarchy (often called a scene graph) is a tree in which each node stores position, rotation and scale **relative to its parent**. The world transform is derived from the root down; with column vectors, `world(child) = world(parent) * local(child)`. So when a character sits in a moving vehicle and holds a weapon at a hand attachment point, gameplay writes only the vehicle's transform each frame and the rider and weapon follow without being touched. Authoring is natural too: a turret's offset on a tank or a door's hinge is expressed in its owner's frame, and attaching or detaching becomes a re-parenting operation that recomputes the local transform so the world pose does not jump. The price is that a world transform is no longer stored as truth: reading it needs every ancestor to be current, and deep chains multiply that work.
go deeper
Recall that children store transforms relative to their parent and that world transforms are derived from the root down, so moving a parent carries the subtree.
Explain the composition rule under a stated vector convention and show how to re-parent an object without it jumping, using the inverse of the new parent's world transform.
Discuss what the hierarchy costs at scale: propagation order, stale world transforms, deep chains, non-uniform scale producing shear, and keeping projectiles and invisible items out of the tree.
Weigh rules a team enforces on hierarchies — maximum depth, no non-uniform scale on parents, flat parents-first storage — against the authoring convenience designers expect from nesting.
## What a transform hierarchy is A **transform** places an object in space: a translation, a rotation and a scale, usually packed into a 4x4 matrix. A **transform hierarchy**, often called a **scene graph**, arranges objects in a tree. Every node has at most one parent, and its transform is stored **relative to that parent** — its **local transform**. The node's **world transform**, where it actually sits in the level, is not stored as the primary value; it is derived by walking from the root down to the node. This answer uses the **column-vector convention**, in which a point is transformed as `M * p` and the transform applied first sits on the right. Under that convention: - `world(root) = local(root)` - `world(child) = world(parent) * local(child)` - applied recursively, a node's world matrix is the product of every local matrix on the path from the root, root on the left. Under the row-vector convention the same rule is written in the opposite order, `local(child) * world(parent)`; the meaning is identical, only the notation flips. The matrix algebra itself — multiplication order, inverses, decomposition — is covered with matrices and transformations. ## Why store the relative transform Consider a character riding a moving vehicle while holding a weapon. The natural tree is vehicle → seat → character → hand attachment point → weapon. 1. Gameplay writes **one** transform per frame: the vehicle's. 2. The seat, character, hand point and weapon keep the same local transforms, because nothing moved *relative to its parent*. 3. Their world transforms are recomputed from the new vehicle transform, so the whole chain moves together, exactly rigidly, with no drift. If every object stored only its world transform instead, gameplay would have to copy the vehicle's motion into each rider and each held item every frame, in the right order, and any rounding or ordering mistake would make the weapon slide out of the character's hand. The hierarchy turns "these things move together" into data rather than code. Other benefits follow from the same idea: - **Authoring in the owner's frame.** A turret is placed at "two metres above the tank's hull, facing forward", which stays true wherever the tank drives. - **Reuse.** A placed group of objects — a market stall with its awnings and crates — can be moved, rotated or duplicated by changing one root. - **Attachment as data.** Picking something up, mounting a vehicle or docking a ship is a change of parent, not a new piece of movement code. ## Attaching and detaching without a jump Re-parenting is where beginners get caught. A node's local transform only has meaning relative to its parent. If a weapon is dropped from the hand to the world root and its local transform is left unchanged, it is now interpreted relative to the root and **teleports** to wherever that old offset lands. To keep the object where it is, recompute the local transform against the new parent at the moment of the change: - `local(new) = inverse(world(newParent)) * world(object)` (column vectors) - if the new parent is a root with the identity transform, this is just the object's current world transform. The opposite case — snapping a picked-up weapon into a grip — deliberately sets the local transform to the authored grip offset instead. ## What the hierarchy costs - **World transforms must be current before they are read.** Something has to propagate parent changes to children each frame, which is why engines pair hierarchies with dirty flags and an update pass. - **Depth multiplies work.** Every level on a chain is one more matrix product, and moving a root dirties its whole subtree. - **Non-uniform scale on a parent can shear a rotated child**, producing a world matrix that no translation-rotation-scale triple can represent; many teams simply forbid non-uniform scale on nodes that have children. - **Memory layout matters.** Nodes scattered across memory turn the update into pointer chasing; storing nodes in a flat array ordered parents-first is the usual fix. ## When not to parent The hierarchy expresses *spatial* relationships, not ownership. A projectile fired from a gun must not stay parented to it, or it will swing with the gun's every movement; spawn it at the muzzle's world transform as a root object. Likewise, an inventory item that is not visible needs no transform parent at all. Keeping trees shallow and parenting only what genuinely moves together is the habit interviewers look for.
- How do you re-parent an object so it stays exactly where it is in the world?Compute its current world transform, then set its local transform to `inverse(world(newParent)) * world(object)` under the column-vector convention before or as you switch parents. If the new parent is an identity root, the local transform simply becomes the old world transform. Leaving the old local values in place makes the object jump, because those values were relative to the previous parent.
- Why can a very deep hierarchy become a performance problem?Each world transform depends on every ancestor's, so a long chain means many matrix products, and moving a node near the root forces its whole subtree to be recomputed. If nodes live at scattered addresses, the update chases pointers and misses the cache. Flattening needless intermediate nodes, storing nodes parents-first in arrays and parenting only what truly moves together keep it cheap.
- Every object stores its world transform and copies its parent's movement each frame.
- A child's world position is its parent's position plus its local position, ignoring rotation.
- Re-parenting only swaps the parent pointer; the object stays where it was.
- A fired projectile should stay parented to the gun that spawned it.
- Composition order does not matter: parent then child equals child then parent.