RealDocs

AActor::ActorGetDistanceToCollision

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: const

Description

Returns the distance from a world-space point to the nearest collision surface on this actor. Returns a negative value if the actor has no primitive with valid collision.

Caveats & Gotchas

  • A return value of 0.0 means the point is either inside the collision shape or on a non-convex surface where closest-point queries are undefined — treat 0.0 as a failure case, not 'touching'.
  • Only components that block the specified TraceChannel are evaluated; components set to Overlap or Ignore for that channel are skipped entirely.

Signature

ENGINE_API float ActorGetDistanceToCollision(const FVector& Point, ECollisionChannel TraceChannel, FVector& ClosestPointOnCollision, UPrimitiveComponent** OutPrimitiveComponent = nullptr) const;

Parameters

Name Type Description Default
Point const FVector& World-space point to measure from.
TraceChannel ECollisionChannel Only components blocking this channel are considered.
ClosestPointOnCollision FVector& Output: the nearest point on the actor's collision surface.
OutPrimitiveComponent UPrimitiveComponent** Optional output: the component that owns the closest point. nullptr

Return Type

float

Example

Find closest point on an actor for AI avoidance C++
FVector ClosestPoint;
UPrimitiveComponent* HitComp = nullptr;
float Dist = TargetActor->ActorGetDistanceToCollision(
    MyPawn->GetActorLocation(),
    ECC_Pawn,
    ClosestPoint,
    &HitComp
);
if (Dist > 0.f)
{
    DrawDebugSphere(GetWorld(), ClosestPoint, 10.f, 8, FColor::Red, false, 1.f);
}

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.