Skip to content

Distance (Vector) / Get Distance To / Distance Squared

At a glance

Lives in: Kismet Math Library for the Vector nodes; Actor for Get Distance To - Returns: a non-negative Real scalar; the Vector helpers are double in current C++, while Actor distance helpers return float - Fails by: Vector math always produces a number; Get Distance To returns 0 silently when Other Actor is None - Official docs: Distance (Vector), Get Distance To, and Distance Squared (Vector)

The one-minute version

  • Distance (Vector) measures the straight-line 3D gap between two points.
  • Get Distance To is the Actor convenience form. It compares the two Actors' Actor locations: their root-component pivots in world space.
  • Distance Squared (Vector) returns the same comparison before the square root. It is not an ordinary distance: world-centimeter inputs produce square centimeters.
  • Compare squared distance with a squared threshold: DistanceSquared <= AttackRange * AttackRange.
  • Get Distance To with a missing Other Actor returns 0 with no warning. Guard the reference first or a missing target can look exactly on top of you.
  • Full 3D distance includes Z. Ground-based games often want 2D/XY distance plus a separate allowed vertical gap.
  • These are pivot-to-pivot measurements. They do not measure collision surfaces, visual bounds, line of sight, or navigation-path length.
  • Skipping the square root matters in a repeated filter over many candidates. Use normal distance when you need to display or otherwise consume the actual measurement; clarity wins for a one-off check.

What the Vector nodes calculate

For two points A and B:

Delta = B - A

Distance(A, B) = sqrt(
    Delta.X * Delta.X
  + Delta.Y * Delta.Y
  + Delta.Z * Delta.Z)

DistanceSquared(A, B) =
    Delta.X * Delta.X
  + Delta.Y * Delta.Y
  + Delta.Z * Delta.Z

The result is one scalar, never a direction. Swapping A and B returns the same distance. Equal points return 0.

Examples:

A B Distance Distance Squared
(0, 0, 0) (3, 4, 0) 5 25
(100, 0, 0) (100, 0, 600) 600 360000
(10, 20, 30) (10, 20, 30) 0 0

The nodes are pure calculations. They do not know whether a Vector represents a world location, velocity, color-like data, or an arbitrary triple. The meaning and units come from the inputs.

For ordinary world locations, Unreal's default world unit is one centimeter:

  • ordinary distance is in centimeters;
  • squared distance is in square centimeters;
  • neither result is automatically converted to meters.

What Get Distance To calculates

Get Distance To packages the common Actor form:

pseudocode - not engine source

if OtherActor exists:
    return Distance(
        TargetActor.GetActorLocation(),
        OtherActor.GetActorLocation())
else:
    return 0

Get Actor Location comes from each Actor's root component. This means the measurement is between Actor pivots, not necessarily between the centers of their visible meshes or collision shapes.

The following can all be different points on one Character:

Actor location       = capsule/root pivot
Mesh world location  = skeletal mesh component origin
Head socket          = animated named point
Camera view          = local/current viewpoint
Impact point         = collision query result

Choose the points that match the gameplay question. If you already have the exact component, socket, camera, or hit locations, feed those Vectors to Distance (Vector) instead of converting them back into Actor pivots.

The missing Other Actor trap

When Other Actor is None, Get Distance To returns 0 silently. It does not return None, emit a success Boolean, take a failure execution path, or log a warning.

This graph is therefore unsafe:

Get Distance To(CurrentTarget) <= AttackRange
-> Attack

If CurrentTarget was never assigned or was destroyed, the distance fallback can satisfy the range check.

Validate identity before geometry:

Is Valid(CurrentTarget)
-> true: Get Distance To(CurrentTarget) <= AttackRange
         -> true: Attack
-> false: clear target / acquire another target

A legitimate distance of zero is possible when two Actor pivots coincide. That is why testing Distance != 0 is not a reference-validity check.

Vector distance has no reference input and therefore no None path. But the objects used to obtain V1 and V2 can still be invalid before the math node runs; guard them at that boundary.

Ordinary distance versus squared distance

The square root turns squared distance into a measurement people recognize. If all you need is an ordering or threshold comparison, that last step is not necessary because squaring preserves the order of non-negative values:

Distance <= Radius

is equivalent to

DistanceSquared <= Radius * Radius

Correct repeated-filter pattern:

RangeSquared = AttackRange * AttackRange   // compute once

For Each Candidate
-> Is Valid(Candidate)
-> Distance Squared(
       Self.GetActorLocation(),
       Candidate.GetActorLocation()) <= RangeSquared
-> keep candidate

Wrong pattern:

Distance Squared(A, B) <= AttackRange

The left side is in squared units and the right side is not. With an attack range of 500, the wrong comparison uses an effective distance of about 22.36, not 500.

Use ordinary distance when:

  • the number is displayed to a player or designer;
  • later math needs the actual distance;
  • a one-time check is clearer with the normal node; or
  • the API you are calling expects an ordinary radius.

Use squared distance when:

  • filtering many points or Actors every update;
  • repeatedly finding the closest candidate while only comparing values; or
  • an existing hot path already stores squared thresholds deliberately.

Avoiding one square root does not excuse repeated world searches, needless Tick work, or an O(N-squared) targeting loop. Fix the larger algorithm first.

3D, 2D/XY, or a separate vertical rule?

Full 3D distance includes X, Y, and Z. That is right for free-space questions:

  • flight and swimming;
  • projectiles and explosions in open 3D space;
  • camera points;
  • arbitrary socket or component positions.

Ground gameplay often cares about horizontal range separately. Use Distance2D (Vector) or Get Horizontal Distance To when vertical separation should not lengthen the horizontal measurement.

Ignoring Z entirely has its own trap: two Actors on different floors but at the same X/Y position have horizontal distance zero. A robust ground-target test often has two rules:

Delta = TargetLocation - SelfLocation

HorizontalDistanceSquared = Delta.X * Delta.X + Delta.Y * Delta.Y
VerticalGap = Abs(Delta.Z)

InRange =
    HorizontalDistanceSquared <= Range * Range
    AND VerticalGap <= MaxVerticalGap

This makes the design explicit: how far across the floor, and how many centimeters above or below are acceptable?

Actor lookalikes include Get Horizontal Distance To, Get Squared Horizontal Distance To, and Get Vertical Distance To. The Vector family has Distance2D (Vector) and Distance2D Squared (Vector).

Pivot distance is not shape distance

Consider two capsule Actors with their pivots 200 centimeters apart. If each capsule has a radius of 50, their closest surfaces are roughly 100 centimeters apart along that simple horizontal line, not 200.

Distance nodes do not inspect:

  • capsule radius or mesh collision;
  • Actor bounds or visible geometry;
  • whether a wall blocks the points;
  • whether the NavMesh has a route between them;
  • socket offsets; or
  • the path an AI agent would actually travel.

Choose a different query when the question differs:

Actual question Better tool
How far between two known points? Distance (Vector)
How far between two Actor pivots? Get Distance To
How far across XY only? Distance2D / Get Horizontal Distance To
How far to collision surface? Closest-point-on-collision query on the relevant Primitive Component
Is the target visible/unblocked? Line or shape trace with the intended collision channel
How long is the traversable AI route? Navigation path query/path length, with failure handling
How far to the muzzle, hand, or head? Get that socket/component location, then Vector distance

Do not subtract bounds extents from pivot distance as a universal surface answer. Bounds are boxes/spheres around geometry, not exact closest collision points, and overlap/rotation can make that shortcut wrong.

The patterns everyone actually uses

Simple Actor range check

Is Valid(CurrentTarget)
-> Get Distance To(CurrentTarget)
-> <= InteractionRange
-> interact / stay out of range

This is readable and appropriate for a single occasional check.

SelfLocation = Get Actor Location
BestDistanceSquared = MaxSearchRange * MaxSearchRange
BestTarget = None

For Each Candidate
-> Is Valid
-> CandidateLocation = Get Actor Location
-> CandidateDistanceSquared = Distance Squared(SelfLocation, CandidateLocation)
-> if CandidateDistanceSquared < BestDistanceSquared:
       BestDistanceSquared = CandidateDistanceSquared
       BestTarget = Candidate

The comparison does not need square roots. If UI later needs the winning distance, take the square root or run normal Distance once for BestTarget.

Ground attack with a floor-height rule

Delta = Target.GetActorLocation - Self.GetActorLocation

HorizontalOK = Vector Length Squared XY(Delta) <= AttackRange * AttackRange
VerticalOK   = Abs(Delta.Z) <= MaxAttackHeightDifference

if HorizontalOK AND VerticalOK:
    continue with line of sight / attack rules

Range alone does not prove visibility, team, alive state, or a valid attack path. Keep each policy as its own named check.

Network and moving-object snapshots

Distance is calculated on the machine that runs the graph from the locations available on that machine at that moment. The node does not ask the server for new transforms or reconcile client prediction.

A client-side HUD range read may be useful presentation. Server-authoritative damage, interaction, or pickup rules must be checked on the server against the server's current authoritative state. Small client/server differences for moving replicated Actors are normal.

Likewise, storing one distance does not make it update. Recompute when the decision needs a fresh snapshot, or update an owned cached value deliberately.

C++ twins

Original example code:

if (!IsValid(CurrentTarget))
{
    return;
}

const FVector SelfLocation = GetActorLocation();
const FVector TargetLocation = CurrentTarget->GetActorLocation();
const double DistanceSquared = FVector::DistSquared(SelfLocation, TargetLocation);

if (DistanceSquared <= FMath::Square(AttackRange))
{
    TryAttack(CurrentTarget);
}

The Actor convenience call is GetDistanceTo(CurrentTarget). It returns a float; current Kismet Vector-distance wrappers expose double results. In Blueprint they are used as Real-number pins, but the semantic distinction that usually matters is ordinary versus squared units.

What these nodes do not do

They do not:

  • validate an Actor reference;
  • return direction from one point to another;
  • test collision, overlap, line of sight, reachability, or team/alive state;
  • measure mesh edges, capsule surfaces, or Actor bounds;
  • choose 2D versus 3D based on your game genre;
  • replicate a result or force current network transforms;
  • keep updating a value after the call; or
  • make a repeated world search cheap merely because the final comparison is squared.

Lookalikes - which one do I want?

Node Returns Use when Watch out
Distance (Vector) 3D distance You already have the two exact points. Includes Z and performs the square root.
Get Distance To 3D Actor-pivot distance You have two valid Actors and want their root locations compared. Missing Other Actor returns 0.
Distance Squared (Vector) Squared 3D distance Repeated threshold/order comparisons. Compare with a squared threshold.
Get Squared Distance To Squared Actor-pivot distance Actor form of the same repeated comparison. Validate Other Actor first.
Distance2D / Get Horizontal Distance To XY distance Vertical separation should not increase horizontal range. Add an explicit vertical limit when floors matter.
Get Vertical Distance To / Abs Delta Z Vertical gap Height is a separate gameplay rule. It says nothing about horizontal range.
Vector Length Magnitude of one offset Vector You already calculated B - A. Length of a raw world location measures from world origin.
Get Unit Direction Vector Direction Vector You need which way from A to B. It discards distance.

Rule of thumb: pick the right points, validate references, choose 3D or an explicit horizontal/vertical policy, then square both sides only when the comparison benefits.

Going deeper