RealDocs

AAIController::LineOfSightTo

function AIModule Since 4.0
#include "AIController.h"
Access: public Specifiers: virtualoverrideAIMODULE_APIconst

Description

Performs a line-trace from the controller's eye position to the target actor to determine visibility. Checks center and top of the target; optionally checks extremities if bSkipExtraLOSChecks is false.

Caveats & Gotchas

  • By default, performs two traces per call (center and top of Other). Setting bSkipExtraLOSChecks = true on the controller reduces this to a single trace, which matters in scenes with many AI agents.
  • The bAlternateChecks flag uses a per-controller rolling flag (bLOSflag) to alternate which extremity is checked each call, spreading cost across frames. A single call is therefore not a complete LOS test when bAlternateChecks is true.

Signature

virtual bool LineOfSightTo(const AActor* Other, FVector ViewPoint = FVector(ForceInit), bool bAlternateChecks = false) const override;

Parameters

Name Type Description Default
Other const AActor* The actor to test visibility against.
ViewPoint FVector Eye position to trace from. If zero, uses the current pawn's view location. FVector(ForceInit)
bAlternateChecks bool When true, alternates traces to extremity points rather than always tracing to the center and top. false

Return Type

bool

Example

Manual LOS check to the player C++
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(this, 0);
if (PlayerPawn && LineOfSightTo(PlayerPawn))
{
	SetFocus(PlayerPawn);
}

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.