RealDocs

AActor::GetTargetLocation

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

Description

Returns the optimal location to fire weapons at or aim towards this actor. The default returns the actor's location; override to provide a specific aim point such as the actor's center of mass or head position.

Caveats & Gotchas

  • The default implementation simply returns GetActorLocation(), which is the root component pivot and often not the ideal aim point for characters. Always override this on pawns or enemies to return a sensible torso/head position.
  • The RequestedBy parameter allows context-sensitive aim points (e.g. targeting a vehicle differently from the front vs. the rear) but most callers pass nullptr, so null-check before using it.

Signature

ENGINE_API virtual FVector GetTargetLocation(AActor* RequestedBy = nullptr) const

Parameters

Name Type Description Default
RequestedBy AActor* The actor requesting the target location; implementations can return different positions based on who is asking. nullptr

Return Type

FVector

Example

Override to return head bone position C++
FVector AMyCharacter::GetTargetLocation(AActor* RequestedBy) const
{
    if (USkeletalMeshComponent* Mesh = GetMesh())
    {
        return Mesh->GetBoneLocation(FName("head"));
    }
    return Super::GetTargetLocation(RequestedBy);
}

Tags

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.