RealDocs

AActor::GetSquaredDistanceTo

function Engine Blueprint Since 4.0
#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
Event Tick Delta Seconds Delta Seconds Branch Condition Condition True False Print String In String Target in range! Target in range! Get Squared Distance To Target is Actor Other Actor Return Value < A B 90000.0 90000.0 Return Value Return Value Target Actor Target Actor Target Actor
Edit Blueprint graph Check if a target actor is within 300 units using squared distance
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
Cheap distance check without sqrt C++
const float TriggerRadiusSq = 300.f * 300.f;
if (MyActor->GetSquaredDistanceTo(PlayerActor) <= TriggerRadiusSq)
{
    // Player is within 300 UU
    ActivateTrigger();
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.