getTransform() vs getActorLocation(), getActorRotation() etc

When I did the challenge, I have used getActorLocation() instead of getTransform(), which immediately gave me an access to location. In the description to that method, it says “Returns the location of the RootComponent of this actor”. Can Root Component be at a different location compared to the actor? Not sure what’s more correct.

3 Likes

All GetTransform() (I feel it should be GetActorTransform() :stuck_out_tongue: ) does is return an FTransform struct, which includes the Location, Rotation, and Scale of the actor all in one package. If you only need the location, I’ll venture to say GetActorLocation() is marginally faster. And the root location is the location of whatever component is the root of the actor. This can be changed, even at runtime.

6 Likes

I have been trying to figure out the subtle differences between these functions as well. After some research I have only found even more methods that provide the same functionality. The list continues to grow:

  1. GetTranslation()
  2. GetLocation()
    3)GetTargetLocation()
    4)GetActorLocation()

Plus using GetActorTransform. Jeez!

I know what you mean. I had made a guess during the challenge of GetActorLocation which worked then watched the video and saw Ben using GetTransform().GetLocation() so switched to that. Not quite sure what the best option is.

I also used GetActorLocation(), plus FString::SanitizeFloat to convert to a string which has the benefit of getting rid of additional zeros in the section after the decimal point:

FString ObjectPos = FString::SanitizeFloat(GetOwner()->GetActorLocation().X) + " for X,  " + FString::SanitizeFloat(GetOwner()->GetActorLocation().Y) + " for Y,  " + FString::SanitizeFloat(GetOwner()->GetActorLocation().Z) + " for Z.";
1 Like

Hey, I ended up doign the same.

FString ObjectPos = GetOwner()->GetActorLocation().ToString();

If memory serves transform structures should be used when modifying something (you are transforming the location).

While GetLocation would be better for just getting the position with no intent to modify

Or am I thinking too much into this?

1 Like

I ended up with the same bit of code as well;

FString ObjectPos = GetOwner()->GetActorLocation().ToString();

Now I was confused as to whether I should use GetActorLocation() or GetTargetLocation(). After reading up on some Unreal docs, it mentions that GetActorLocation() returns the “root location” of the actor. The GetTargetLocation() returns the location for which weapons would be fired at. I think using GetActorLocation() is probably a better practice for the time being as though GetTargetLocation() would be used later on in an FPS setting.

1 Like

Privacy & Terms