C++ question

Hi there! I want to know if this:

myPivotCar->SetRelativeRotation( FRotator( 0.f,UKismetMathLibrary::FInterpTo(myPivotCar->GetRelativeRotation().Yaw, mySkidCurve->GetFloatValue( UKismetMathLibrary::Clamp( UKismetMathLibrary::Dot_VectorVector(myMesh->GetPhysicsLinearVelocity(), myMesh->GetRightVector())/200.f,-1.f,1.f)),GetWorld()->GetDeltaSeconds(),5.f),0.f));

is more optimized than this or is the same just harder to read :slight_smile:

	FVector linVel = myMesh->GetPhysicsLinearVelocity();

	FVector rightVec = myMesh->GetRightVector();

	float dotResults = UKismetMathLibrary::Dot_VectorVector(linVel,rightVec);

	mySkidVal = UKismetMathLibrary::Clamp(dotResults/200.f,-1.f,1.f);

	float pivotKartYaw = myPivotCar->GetRelativeRotation().Yaw;

	pivotKartYaw = UKismetMathLibrary::FInterpTo(pivotKartYaw, mySkidCurve->GetFloatValue( mySkidVal), GetWorld()->GetDeltaSeconds(),5.f);

	myPivotCar->SetRelativeRotation(FRotator(0.f,pivotKartYaw,0.f));
1 Like

Hey!
Most of the operations done inline are stored in separate variables when passed as a function argument. This is guaranteed when the function accepts a reference or a const reference like this:
Foo(const FVector& arg)
So the former is not more optimized; it is simply more difficult to read.
When compiling this:

int i, j, k;
int f = i + j * k;

it will be translated to this by the compiler:

int i;
int j;
int k;
int _a = j * k;
int f = i + _a;
3 Likes

Thanks @SamiMD !

1 Like

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