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

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…

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?

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

Hey -

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

Cheers

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.