Why do we use Fstring for numbers here?

using the code:

FString ObjectPosition = GetOwner()->GetActorLocation().ToString();
	UE_LOG(LogTemp, Warning, TEXT("The Object %s, is at position: %s,"), *ObjectName, *ObjectPosition);

I don’t fully understand why this isn’t an int32 instead?
Is FString used for integers too?

Also, not sure what:
GetActorLocation().ToString();
This: .ToString();
I have no idea what I’m doing with adding this and therefor couldn’t do the tast. Did we learn this already? How does it work? Thanks!

Hi friend - the reason you need an FString for this is because the function GetActorLocation returns an FVector, which will be represented as a collection three floats. Since it’s three floats, the FString returned by ToString() will contain characters other than just the floats (namely punctuation and the assigned characters X,Y,Z ).

The “.” operator is a way to access functions / variables that are contained within other classes / structs. So .ToString() is just a function that is in the FVector struct that turns a set of coordtinates into a readable String.

See : FVector::ToString | Unreal Engine Documentation

Hope this helps - keep at it!
Cheers,
Tele

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms