# How to use compose transform

**URL:** <https://forums.unrealengine.com/t/how-to-use-compose-transform/1792541>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine, Blueprint, question, CPP\
**Created:** [April 7, 2024, 3:07pm UTC](https://forums.unrealengine.com/t/how-to-use-compose-transform/1792541 "2024-04-07T15:07:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![const\_v\_cast](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@const\_v\_cast](https://forums.unrealengine.com/u/const_v_cast)\
**Post date:** [April 7, 2024, 3:07pm UTC](https://forums.unrealengine.com/t/how-to-use-compose-transform/1792541/1 "2024-04-07T15:07:07Z")

</div>

Can anyone explain what is usage/purpose of compose transform and invert transform functions? Any examples?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/6/f/66fda20dbd9dab18d2715255b4a035f78e0d9346.png)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [April 7, 2024, 5:23pm UTC](https://forums.unrealengine.com/t/how-to-use-compose-transform/1792541/2 "2024-04-07T17:23:23Z")

</div>

Compose transform just applies the first, then the second transfrom.

Invert transform just reverses a transform.

---

<div class="post-metadata">

**Author:** ![MJATR](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MJATR](https://forums.unrealengine.com/u/MJATR)\
**Post date:** [April 28, 2024, 2:52pm UTC](https://forums.unrealengine.com/t/how-to-use-compose-transform/1792541/3 "2024-04-28T14:52:31Z")

</div>

> TLDR

If you want to know the **Child** → **Parent** transform you use **Child → Get Relative Transform** and if you want to know the **Parent** → **Child** transform you use **Child → Get Relative Transform → Invert Transform**. But if you want to know **A** → **B** when there is not a direct **Child-Parent** connection **[1]**, like in the **Link** → **Base** there is **Joint** in between, in this case you need to **Compose Transform**. That is **Link(A)** and **Joint(B)** call **Compose Transform (A,B)** will give **Link** → **Base** Transform, that is because  
**Link** → **Joint** → **Base** is the relative transform chain **[1]**. If you call **Compose Transform (B,A)** that will consider that both the **Joint** and the **Link** transforms are relative to the **Base** , that is they both have **Base** as their direct **Parent** **[2]**.

It is easier to use the **Get World Transform** when you want to know the relative transform of a **Actor/Component** relative to some other **Actor/Component** when there is no direct connection **[3]**.

So, if you want to know the relative transform of **MeshD** → **Link** you need to use:

 ![GeneralChildParent](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/0/c/60c16e134f4c186e3afcac7e256263663b18e863.png)

What you want as a **Child** goes in the **A** pin and the **Parent** goes in the **B** pin, and then you will have **Child** → **parent** transform, note that you need the **Invert Transform** of the **Parent** and both **A** and **B** are **World Transform**.

1. ![ActorComponents](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/a/59aab2abd1fb2d6ba74232f82a46e95398a53eb2.png)
2. ![SameParent](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/2/2/c22aca8158b4efae8a48d898a575c4125a361b60.png)
3. ![WorldCompose](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/1/d/b1dec288df2b4b6ea00df3bc787af1adf20bd3a2.png)

> Long Answer

First you need to understand the difference between _Fixed Reference Frame_ and _Moving Reference Frame_.

All transforms are relative to something. The **Get Relative Transform** is relative to the **Actor/Component** parent, while **Get World Transform** is relative to the World _Fixed Reference Frame_.

By default any Local Transform are done in _Euler-ZYX_ notation, that is a _Moving Reference Frame_, also called _Local Frame_.

So let’s take a simple example.

Here we have a simple **Actor** with 3 **Static Mesh Component**.

![ActorComponents](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/9/a/59aab2abd1fb2d6ba74232f82a46e95398a53eb2.png)

If you want to know the relative transform just call the **Get Relative Transform** directly.

![RelativeTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/a/5faba12e2ad80e22cfe627fa6bacae4490ebddd8.png)

The **Base** transform is relative to the world due to it beeing the **Root Component**.  
The **Joint** transform is relative to the **Base**.  
The **Link** transform is relative to the **Joint**.

> But what if you want to know the transform of the **Link** relative to the **Base**?
> 
> You need to **Compose Transform**.

**Joint** Transform.  
 ![JointTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/7/227bf8cd080d9f8297849ae2a4c9060ab1f0f0ca.png)

**Link** Transform.  
 ![LinkTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/c/f/dcf0fadb56b6f9a789b1b7397f3368819a3c1158.png)

> Obs: if you test it and print the transform and see some weird values that is because you have more than 90 degree rotation in _Y(pitch)_ axis, and **Unreal** have some problems with that, so just use 89.5 as a test value like in the **Link** transform.

Transform Frames.

 ![axis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/f/d2fc84c11e9372b2d9e26e808b817e812e1185f8.png)

So, what happens if we use **Compose Transform** with the **Joint** and the **Link**?

![TestCompose](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/4/4/a44f91e64bd967fd2afcd19ba29dee973c201934.png)

Result Transform.  
 ![ResultComposeTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/5/2/65238e9a36e2f63745f0b49ecbdf90989e3b8a05.png)

What **Compose Transform** does is to first apply _A_ the **Joint** transform then it applies _B_ the **Link** transform. If you notice the _Z_ axis just got add together, but the _Z_ axis of the **Link** transform is actualy in the _Y_ direction of the **Base** Frame.

The 100 in _Z_ axis of the **Link** transform is relative to the **Joint** Frame.

> So what **Compose Transform** did was to consider that both the **Joint** and the **Link** transform were relative to the **Base** , but in this case that would be wrong.

But if we want to know the transform of the **Link** relative to the **Base** , we need to switch the pins.

![CorrectTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/b/5/4b5b932ab9f7a54b55974f0690bfac8a2d4d04ba.png)

That is because **Unreal** Invert the transforms in code.

_KismetMathLibrary.h_ more precisely_TransformVectorized.h_  
 ![TransformMultiplication](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/8/f/48feafd8ce5b8e9696fd1e240a85c688962d9af2.png)

That is necessary because in math you do matrix multiplication from right to left, so _A_ is applied first then _B_.

Result Transform.  
 ![Transform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/1/8919a3a8057c7d358d67d63721e77f514f63d8a1.png)

Now we can see that the **Link** Frame is 100 in _Y_ axis and 150 in _Z_ axis that is relative to the **Base** Frame. And the rotations also are correct, it is an _Euler-ZYX_ rotation of _Z(0),Y(-90),X(90)_. It takes the **Base** Frame and transform it in the **Link** Frame.

Now that we have the **Link** Frame relative to the **Base** Frame, what if we want the **Base** relative to the **Link**? Just use the **Invert Transform**.

 ![InvertTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/1/b/31b5ed78a1081f86f260e3230c563d04b2401de9.png)

Result Transform.  
 ![NewTransform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/a/7/8a7920fe5ef74dd97e10b43ff7cb1e616d89dedf.png)

You can also achieve the same result using **Get World Transform**

So if you want to know the **Link** → **Base** transform you can **Compose Transform** all elements in the chain, like **Link** → **Joint** → **Others** → **Base** , but because you have the **World** Frame as a common Frame for all transforms, you can simply compose two **Actor/Component** directly.

 ![NewChildParent](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/a/a6abd0543f8cca8fc101f989e22db05dbae25cc2.png)

This will result in **Link** → **Base** transform in the same way that **Compose Transform** the **Link** and **Joint** relative tranform.

In general the math is as follow.

> B = Base Frame.  
> L = Link Frame.  
> W = World Frame.
> 
> BLT = Link relative to Base transform **Link** → **Base**.
> 
> WBT = Base relative to World transform **Base** → **World**.
> 
> BWT = (WBT)-1 = World relative to Base transform **World** → **Base** , just apply **Invert Transform** to the **Base** → **World** transform.
> 
> WLT = Link relative to World transform **Link** → **World**.
> 
> BLT = BWT \* WLT
