AActor::GetDistanceTo
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Returns the world-space distance in centimetres between this actor's origin and OtherActor's origin.
Signature
float GetDistanceTo(const AActor* OtherActor) const Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OtherActor | const AActor* | The actor to measure distance to. | — |
Return Type
float Caveats & Gotchas
- • Distance is calculated from the actor's root component origin, not from its collision bounds or mesh surface. For large actors this can be misleading.
- • Involves a square root — if you're doing many comparisons in a loop, use GetSquaredDistanceTo and compare against the squared threshold instead.
- • Returns 0 if OtherActor is null.
Example
Check if player is in range C++
APlayerController* PC = GetWorld()->GetFirstPlayerController();
if (PC && PC->GetPawn())
{
float Dist = GetDistanceTo(PC->GetPawn());
if (Dist < 500.f)
{
// within 5 metres
}
} See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?