RealDocs

UKismetMathLibrary::FloatSpringInterp

function Engine Blueprint Since 4.0
#include "Kismet/KismetMathLibrary.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Interpolates a float from Current toward Target using a physically-based spring-damper model, driven by SpringState which persists velocity and previous-target data across calls. Produces smoother, more natural motion than FInterpTo for values that need momentum, like camera shake recovery or UI element settling.

Caveats & Gotchas

  • SpringState must be a persistent variable unique to this particular spring (e.g. a member variable) — passing a freshly constructed FFloatSpringState each call resets the spring's momentum every frame and defeats the purpose.
  • This is BlueprintCallable, not BlueprintPure, because it mutates SpringState as an output ref parameter; pure-function caching would give stale or incorrect results.
  • Call ResetFloatSpringState when you want to reset the spring's velocity and previous-target tracking, e.g. after teleporting the tracked object, otherwise a large discontinuity will cause a visible snap or overshoot.

Signature

static float FloatSpringInterp(float Current, float Target, UPARAM(ref) FFloatSpringState& SpringState, float Stiffness, float CriticalDampingFactor, float DeltaTime, float Mass = 1.f, float TargetVelocityAmount = 1.f, bool bClamp = false, float MinValue = -1.f, float MaxValue = 1.f, bool bInitializeFromTarget = false)

Parameters

Name Type Description Default
Current float Current value.
Target float Target value.
SpringState FFloatSpringState& Persistent spring state (velocity, previous target, etc). Use a unique variable per spring.
Stiffness float How stiff the spring model is — higher values oscillate more around the target.
CriticalDampingFactor float Damping applied to the spring: 0 means no damping, 1 means critically damped (no oscillation).
DeltaTime float Time since the last update.
Mass float Multiplier that acts like mass on the spring. 1.f
TargetVelocityAmount float At 1, the target's velocity is factored in so the spring follows closely without lag; values toward 0 progressively disable this and are recommended when smoothing noisy data. 1.f
bClamp bool Whether to clamp the output using MinValue/MaxValue. false
MinValue float Minimum output value; velocity is cancelled if this limit is reached. -1.f
MaxValue float Maximum output value; velocity is cancelled if this limit is reached. 1.f
bInitializeFromTarget bool If set, the current value is initialized from Target on the first update instead of starting from Current. false

Return Type

float

Example

Spring-smooth a camera FOV toward a target value C++
// FFloatSpringState FOVSpringState; // member variable, persists across ticks
void AMyCamera::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    CurrentFOV = UKismetMathLibrary::FloatSpringInterp(CurrentFOV, TargetFOV, FOVSpringState, 100.f, 0.5f, DeltaTime);
    CameraComponent->SetFieldOfView(CurrentFOV);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.