AActor::GetSquaredHorizontalDistanceTo
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableconst
Description
Returns the squared 2D (horizontal) distance between this actor and OtherActor, ignoring Z. The cheapest distance check when you only care about the XY plane.
Caveats & Gotchas
- • Returns squared units — compare against a squared threshold (e.g., 200.f * 200.f, not 200.f) or the comparison will be wrong.
- • Does not guard against a null OtherActor — passing null will crash.
Signature
ENGINE_API float GetSquaredHorizontalDistanceTo(const AActor* OtherActor) const; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OtherActor | const AActor* | The other actor to measure squared horizontal distance to. | — |
Return Type
float Example
Fast horizontal proximity check in a loop C++
const float RangeSq = AggroRadius * AggroRadius;
for (AActor* Enemy : NearbyEnemies)
{
if (Enemy->GetSquaredHorizontalDistanceTo(Player) < RangeSq)
{
Enemy->SetHostile(Player);
}
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?