X, Y and Z as separate variables

I’ve tried a different approach, got all the required location data as separate X, Y and Z float variables:

FVector ActorVector= GetOwner()->GetActorLocation();

UE_LOG(LogTemp, Warning, TEXT(“Actor is at position X: %f, Y: %f, Z: %f”), ActorVector.X, ActorVector.Y, ActorVector.Z);

2 Likes

cool, yes me too, reached to that approach:)

AActor* Object = GetOwner(); // making an instance of AActor (if I am not wrong !)

FString Objectname = Object->GetName(); //extracting its name

FTransform ObjectTransform = Object->GetActorTransform(); //extracting its full world transofrmation “location, rotation and scale”

FVector ObjectLocationXYZ = ObjectTransform.GetLocation(); //Extracting only the World-location and assign it to a vector

//extracting each component of this vector from Struct FVector, directly by calling its variables X, Y, and Z…the way we learned in struct section

float ObjectPoseX = ObjectLocationXYZ.X;

float ObjectPoseY = ObjectLocationXYZ.Y;

float ObjectPoseZ = ObjectLocationXYZ.Z;

//Printing out the result. %g if I am not wrong will capture the float(?)

UE_LOG(LogTemp , Warning , TEXT(“The X, Y, Z Location of Object %s is : %g, %g, %g”) , *Objectname , ObjectPoseX , ObjectPoseY , ObjectPoseZ );

Same :grin:. I had this:

FVector ObjectPosition = GetOwner()->GetActorLocation();
UE_LOG(LogTemp, Warning, TEXT("X: %f. Y: %f. Z: %f."), ObjectPosition.X, ObjectPosition.Y, ObjectPosition.Z);

While this does work, you should consider using the Vector3 type for technical reasons. The float[3] data structure is used specifically by central processing units (CPUs) SMD registers to perform 3D math in single operations. That is to say, if you’re using Vector3 to do a transform against another Vector3, what happens is the arrays are loaded into special registers and then a single operation is executed against them to get all three values calculated at once. This effectively reduces the amount of time it takes to make a triangle calculation by 2/3rds. Or, not using it increases the amount of time it takes to do such a calculation by 300%! Definitely use the Vector3! :slight_smile:

Privacy & Terms