UKismetMathLibrary::Vector_DistanceSquared
#include "Kismet/KismetMathLibrary.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the squared Euclidean distance between two 3D points without computing a square root. Preferred over Vector_Distance when only comparing distances.
Caveats & Gotchas
- • The returned value is distance-squared, not distance. Compare against a squared threshold (e.g., Range * Range), not the raw range value — a common bug is comparing the result directly to an unsquared radius.
- • The squared distance grows much faster than linear distance, so it cannot be used for lerping or display — convert to real distance with FMath::Sqrt when a human-readable value is needed.
Signature
static UE_INL_API double Vector_DistanceSquared(FVector V1, FVector V2); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| V1 | FVector | The first point. | — |
| V2 | FVector | The second point. | — |
Return Type
double Example
Efficiently check if enemy is within aggro range C++
double DistSq = UKismetMathLibrary::Vector_DistanceSquared(
EnemyAI->GetActorLocation(),
Player->GetActorLocation());
if (DistSq <= AggroRange * AggroRange)
{
EnemyAI->StartChasing(Player);
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?