RealDocs

UKismetMathLibrary::Distance2D

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

Description

Returns the Euclidean distance between two 2D points. Involves a square root — use DistanceSquared2D for distance comparisons to avoid the sqrt cost.

Caveats & Gotchas

  • This calls FMath::Sqrt internally. For range checks (is A closer than X?), compare DistanceSquared2D against X*X to avoid the square root entirely.
  • Not to be confused with Vector_Distance2D, which takes two FVector (3D) inputs and computes distance in the XY plane only, ignoring Z.

Signature

static UE_INL_API double Distance2D(FVector2D V1, FVector2D V2);

Parameters

Name Type Description Default
V1 FVector2D The first 2D point.
V2 FVector2D The second 2D point.

Return Type

double

Example

Check if a UI element is near the cursor C++
FVector2D CursorPos(400.f, 300.f);
FVector2D ElementPos(410.f, 295.f);
double Dist = UKismetMathLibrary::Distance2D(CursorPos, ElementPos);
if (Dist < HoverRadius)
{
    HighlightElement();
}

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.