Unreal Engine 5 · Blueprint → C++
Get Distance To in Unreal Engine 5 C++UE Docs
The Get Distance To Blueprint node is AActor::GetDistanceTo in C++. It returns the distance in Unreal units between this actor's location and OtherActor's location as a float.
Blueprint node & C++ equivalent
float Distance = GetDistanceTo(OtherActor);What does the Get Distance To node do?
Get Distance To calculates the straight-line (Euclidean) distance between the calling actor and another actor, using their world-space root locations. The result is returned in Unreal units (centimeters by default), which makes it ideal for range checks, AI awareness, and proximity triggers.
Internally it is equivalent to taking the magnitude of the vector between GetActorLocation() and OtherActor->GetActorLocation().
The C++ equivalent
In C++ you call the member function directly on an actor instance: float Distance = GetDistanceTo(OtherActor);. GetDistanceTo is declared on AActor, so any actor or subclass can call it without including extra headers.
Always validate OtherActor before calling — passing a null pointer will crash. A safe pattern is if (OtherActor) { float Distance = GetDistanceTo(OtherActor); }.
When to use it in C++
Use GetDistanceTo for simple 3D distance comparisons such as deciding whether an enemy is close enough to attack. If you only care about horizontal distance, use GetHorizontalDistanceTo instead, which ignores the Z axis. For performance-critical comparisons against a threshold, compare squared distances with FVector::DistSquared to avoid the square root.
Frequently asked questions
What units does GetDistanceTo return in UE5?+
It returns the distance in Unreal units (centimeters by default), as a float.
How do I get the horizontal distance between two actors in C++?+
Use AActor::GetHorizontalDistanceTo(OtherActor), which measures distance on the XY plane and ignores the Z (vertical) axis.