Download

FTransform not moving the actor?

Hi there,

I just started out using Unreal (coming from Unity), and i’m having troubles understanding the FTransform of an AActor (new class inherited from UActorComponent).

I tried to set the Translation/Rotation of the Object in the Scene like that:
GetOwner()->GetActorTransform().SetTranslation(FVector(0, 0, 0));

According to the documentation, this should set new values for the translation component, but for some reason, it doesnt change anything. Yet, calling this returns the correct values:
GetOwner()->GetActorTransform().GetTranslation();

This seems to work:
GetOwner()->SetActorLocation(FVector(0, 0, 0));

Why can’t i manipulate the Transform directly?

Thanks upfront!

Because it’s a const reference (FTransform const& or equivalently const FTransform &). I’m surprised that you said

because that code should result in a compilation error, since *FTransform::SetTranslation *is a non-const method.

From Actor.h:



class ENGINE_API AActor : public UObject
{

...

    /** Returns the transform of the RootComponent of this Actor*/
    FORCEINLINE const FTransform& GetActorTransform() const
    {
        return TemplateGetActorTransform(RootComponent);
    }


Hmm… thats interesting. Perhaps i should mention, that i’m using UE v4.21.2 of the editor. On my end, the function in Actor.h looks like this (not returning a const reference - thus probably no compiler error):


  
    /** Returns the transform of the RootComponent of this Actor*/
    FORCEINLINE FTransform GetActorTransform() const
    {
        return TemplateGetActorTransform(RootComponent);
    }


Perhaps this was changed in a recent update?
Either way, in my current version its returning a “struct FTransform”, that seems to hold the correct values…

I know i should probably update to the newest version, but i thought it would be odd, if something as fundamental as this function wasn’t working as intended up until recent updates…

I guess the only explanaition would be that the function returns a new FTransform instance (a clone of the searched FTransform), instead of the actual “ActorTransform”?

Yes, that would return the FTransform struct by value, so any change you make to it only affects the temporary copy, not the one the actor is using.

Yeah you can’t modify a transform in-place like that, you need to call SetActorTransform() and provide a new transform, which will set the transform of the root component and update all child components too.