AActor::GetSquaredDistanceTo
#include "GameFramework/Actor.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallableconst
Description
Returns the squared 3D distance between this actor and OtherActor. Prefer this over GetDistanceTo when comparing distances, since it avoids a square root calculation.
Caveats & Gotchas
- • Returns squared units (Unreal units squared), so you must compare against a squared threshold — e.g., use 10000.f (100 UU squared) instead of 100.f.
- • Does not guard against a null OtherActor — passing null will crash. Always validate the pointer first.
Signature
ENGINE_API float GetSquaredDistanceTo(const AActor* OtherActor) const; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| OtherActor | const AActor* | The other actor to measure distance to. | — |
Return Type
float Examples
Check if a target actor is within 300 units using squared distance
Blueprint
Cheap distance check without sqrt C++
const float TriggerRadiusSq = 300.f * 300.f;
if (MyActor->GetSquaredDistanceTo(PlayerActor) <= TriggerRadiusSq)
{
// Player is within 300 UU
ActivateTrigger();
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?