AActor::GetHorizontalDistanceTo
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableconst
Description
Returns the 2D (horizontal) distance between this actor and OtherActor, ignoring Z height. Useful for ground-plane proximity checks where vertical offset should not matter.
Caveats & Gotchas
- • Performs a square root internally, making it more expensive than GetSquaredHorizontalDistanceTo. Use the squared version when comparing distances in tight loops.
- • Does not guard against a null OtherActor — passing null will crash.
Signature
ENGINE_API float GetHorizontalDistanceTo(const AActor* OtherActor) const; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OtherActor | const AActor* | The other actor to measure horizontal distance to. | — |
Return Type
float Examples
Print a message when an NPC is within 150 units horizontally
Blueprint
Check if NPC is within interaction range ignoring height C++
if (NPC->GetHorizontalDistanceTo(Player) < 150.f)
{
NPC->StartDialogue();
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?