RealDocs

FMath::Lerp

function Core Since unknown
#include "Math/UnrealMathUtility.h"
Access: public Specifiers: staticconstexpr

Description

Linearly interpolates between two values. Alpha is not clamped — values outside [0, 1] extrapolate beyond A and B.

Signature

template< class T, class U >
static constexpr UE_FORCEINLINE_HINT T Lerp(const T& A, const T& B, const U& Alpha)

Parameters

Name Type Description Default
A T The start value (returned when Alpha is 0).
B T The end value (returned when Alpha is 1).
Alpha U The interpolation factor, typically in [0, 1].

Return Type

T

Caveats & Gotchas

  • Alpha is unclamped. Pass FMath::Clamp(Alpha, 0.f, 1.f) explicitly if you need to guarantee the result stays between A and B.
  • For smooth frame-rate-independent interpolation, use FMath::FInterpTo instead — Lerp with a time-based alpha will drift as frame rate changes.
  • FQuat has a specialised TCustomLerp implementation that performs NLerp rather than component-wise lerp. For correct quaternion blending use FQuat::Slerp.

Example

Blend two colours and two floats C++
// Blend two colours based on damage fraction
float DamageFraction = FMath::Clamp(1.0f - (Health / MaxHealth), 0.0f, 1.0f);
FLinearColor DisplayColor = FMath::Lerp(FLinearColor::Green, FLinearColor::Red, DamageFraction);

// Lerp a FOV between two camera presets
float CurrentFOV = FMath::Lerp(DefaultFOV, AimFOV, AimAlpha);

Tags

Version History

Introduced in: unknown

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.