RealDocs

UKismetMathLibrary::FindNearestPointsOnLineSegments

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

Description

Finds the pair of closest points between two finite line segments, one point per segment. Useful for rope proximity checks, nearest-path queries, or collision pre-tests.

Caveats & Gotchas

  • Results are via output parameters, not a return value. In Blueprint, forgetting to wire the output pins Segment1Point and Segment2Point is a common mistake.
  • When segments are parallel or co-linear the nearest-point pair is not unique. The function returns a deterministic but arbitrary result — do not rely on it being the midpoint of the overlap.

Signature

static UE_INL_API void FindNearestPointsOnLineSegments(FVector Segment1Start, FVector Segment1End, FVector Segment2Start, FVector Segment2End, FVector& Segment1Point, FVector& Segment2Point);

Parameters

Name Type Description Default
Segment1Start FVector Start of the first segment.
Segment1End FVector End of the first segment.
Segment2Start FVector Start of the second segment.
Segment2End FVector End of the second segment.
Segment1Point FVector& Output: closest point on segment 1 to segment 2.
Segment2Point FVector& Output: closest point on segment 2 to segment 1.

Return Type

void

Example

Measure the gap between two rail segments C++
FVector P1, P2;
UKismetMathLibrary::FindNearestPointsOnLineSegments(
    Rail1Start, Rail1End, Rail2Start, Rail2End, P1, P2);
float GapDist = FVector::Dist(P1, P2);
if (GapDist < 50.f) { UE_LOG(LogTemp, Warning, TEXT("Rails nearly intersect")); }

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.