# GetRelativeTransform on StaticMeshComponent returns world transform instead of relative transform when physics is enabled

**URL:** <https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965>\
**Category:** World Creation\
**Tags:** bug, unreal-engine, CPP, question\
**Created:** [April 30, 2016, 12:02am UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965 "2016-04-30T00:02:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_6fcbe82e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6fcbe82e](https://forums.unrealengine.com/u/anonymous_user_6fcbe82e)\
**Post date:** [April 30, 2016, 12:02am UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965/1 "2016-04-30T00:02:10Z")

</div>

It seems that GetRelativeTransform() on a StaticMeshComponent returns the world transform when physics is enabled, instead of the relative transform.

To recreate this:

Create C++ class, with a UPROPERTY UStaticMeshComponent.

Create a blueprint based on this class

Create a staticmeshcomponent with some static mesh in the blueprint

Enable physics on the staticmeshcomponent

Assign the created staticmeshcomponent to the uproperty in the construction script

in C++, call GetRelativeTransform on the staticmeshcomponent, and it will give the worldtransform instead of the relative transform.

(I think it’s likely the same problem is there when only blueprints are used…)

This does not happen if you have physics disabled…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [May 2, 2016, 2:50pm UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965/2 "2016-05-02T14:50:22Z")

</div>

Hey -

Just for reference, are you getting the world transform of the static mesh component or the actor itself? Can you show what the values you’re getting are when physics is/is not turned on? Also, can you post the code that you’re using in both your header and source file?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6fcbe82e](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6fcbe82e](https://forums.unrealengine.com/u/anonymous_user_6fcbe82e)\
**Post date:** [May 2, 2016, 8:54pm UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965/3 "2016-05-02T20:54:30Z")

</div>

I’m getting the transform of the component.  
This is the setup:  
The actor sits at: (X=-60.000000,Y=40.000000,Z=20.000000)  
In the actor I made has a cube at (X=0.000000,Y=0.000000,Z=420.000000), which the c++ has a reference to.

Header file:

```
    #pragma once
    
    #include "GameFramework/Actor.h"
    #include "MyActor.generated.h"
    
    UCLASS()
    class TESTBUG_API AMyActor : public AActor
    {
    	GENERATED_BODY()
    public:	
    	AMyActor();
    	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "mesh")
    	UStaticMeshComponent* comp;
    	virtual void BeginPlay() override;
    	virtual void Tick( float DeltaSeconds ) override;
    };

```

cpp file:

```
#include "TestBug.h"
#include "MyActor.h"

AMyActor::AMyActor()
{
	PrimaryActorTick.bCanEverTick = true;
}

void AMyActor::BeginPlay()
{
	Super::BeginPlay();
	UE_LOG(LogTemp, Warning, TEXT("world transform=%s"), *comp->GetComponentTransform().ToString());
	UE_LOG(LogTemp, Warning, TEXT("relative transform=%s"), *comp->GetRelativeTransform().ToString());
}

void AMyActor::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );
}

```

When I run it without physics enabled on the cube, the output log shows:

LogTemp:Warning: world  
transform=-60.000000,40.000000,440.000000|0.000000,0.000000,-0.000000|1.000000,1.000000,1.000000  
LogTemp:Warning: relative  
transform=0.000000,0.000000,420.000000|0.000000,0.000000,-0.000000|1.000000,1.000000,1.000000

When I run it with physics enabled on the cube it shows:

LogTemp:Warning: world transform=-60.000000,40.000000,440.000000|0.000000,0.000000,-0.000000|1.000000,1.000000,1.000000  
LogTemp:Warning: relative transform=-60.000000,40.000000,440.000000|0.000000,0.000000,-0.000000|1.000000,1.000000,1.000000

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [May 3, 2016, 3:17pm UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965/4 "2016-05-03T15:17:11Z")

</div>

Hey -

I was able to reproduce the behavior you mentioned and have entered a bug report (UE-30252) for further investigation.

Cheers

---

<div class="post-metadata">

**Author:** ![Dig\_Squid](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/dig_squid/32/1145423_2.png) [@Dig\_Squid](https://forums.unrealengine.com/u/Dig_Squid)\
**Post date:** [May 4, 2016, 7:32am UTC](https://forums.unrealengine.com/t/getrelativetransform-on-staticmeshcomponent-returns-world-transform-instead-of-relative-transform-when-physics-is-enabled/355965/5 "2016-05-04T07:32:21Z")

</div>

This is actually expected. When something simulates, we detach it, because it needs to move free from it’s parent. Once it is detached, its relative transform is related to the world, hence the result you are seeing.
