Is FInterpTo better than Lerp for performance??

Hello well… the title says it all I was just wondering that because I saw some people were saying Lerp is worse for performance and to go to the alternative FInterpTo or FInterpConstantTo. is that true?? idk im just thinking why not put a clamp on it but hey what do I know any advice would be much appreciated.

Thx in advance Cheers :slight_smile:

Unless you’re calling them thousands of times a second, I wouldn’t worry about it, the performance difference is going to be negligible considering everything else that’s going on.

As an aside, Lerp is a much cheaper operation as it is much simpler, just look at the implementation yourself;

template< class T, class U > 
    static FORCEINLINE_DEBUGGABLE T Lerp( const T& A, const T& B, const U& Alpha )
        return (T)(A + Alpha * (B-A));

CORE_API float FMath::FInterpTo( float Current, float Target, float DeltaTime, float InterpSpeed )
    // If no interp speed, jump to target value
    if( InterpSpeed <= 0.f )
        return Target;

    // Distance to reach
    const float Dist = Target - Current;

    // If distance is too small, just set the desired location
    if( FMath::Square(Dist) < SMALL_NUMBER )
        return Target;

    // Delta Move, Clamp so we do not over shoot.
    const float DeltaMove = Dist * FMath::Clamp<float>(DeltaTime * InterpSpeed, 0.f, 1.f);

    return Current + DeltaMove;

They are for different things.

Lerp() is for when you already know alpha from [0 - 1], for example in timed interpolations

InterpTo() is sort of an “approach algorithm” it moves at some speed, then checks “am I there yet?”

Use Lerp() when you want to “move object X from location A to location B in time T”

Use InterpTo() when you want to “move object X toward (potentially moving) location A at Speed S and stop when you get there”

Shmoopy1701, ambershee Thank You soo much this was very informative I will for sure take all of that into consideration

Thx again Cheers :slight_smile: