RealDocs

UKismetMathLibrary::ClampVectorSize

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

Description

Returns a copy of a vector with its magnitude (length) clamped between Min and Max, preserving direction. Commonly used to enforce speed limits or bounded forces while keeping the movement direction intact.

Caveats & Gotchas

  • • If the input vector is near-zero, direction is undefined and the result may snap to an arbitrary direction when scaled up to Min. Guard against zero-length input when Min > 0.
  • • Both Min and Max clamp the *magnitude*, not individual components — this is different from FVector::BoundToCube or component-wise clamping.
  • • Passing Min > Max produces undefined results; always ensure Min <= Max.

Signature

static UE_INL_API FVector ClampVectorSize(FVector A, double Min, double Max);

Parameters

Name Type Description Default
A FVector The input vector. —
Min double Minimum magnitude. If the vector's length is less than Min, it is scaled up to Min. —
Max double Maximum magnitude. If the vector's length is greater than Max, it is scaled down to Max. —

Return Type

FVector

Example

Enforce velocity bounds on a movement vector C++
FVector Velocity = ComputeDesiredVelocity();
// Keep speed between 100 and 600 cm/s
FVector ClampedVelocity = UKismetMathLibrary::ClampVectorSize(Velocity, 100.0, 600.0);

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.