RealDocs

AAIController::SetFocus

function AIModule Since 4.8
#include "AIController.h"
Access: public Specifiers: virtualAIMODULE_API

Description

Sets an actor as the AI's focus target at the given priority slot. The pawn's control rotation continuously tracks GetFocalPointOnActor(NewFocus) each tick, following the actor as it moves.

Caveats & Gotchas

  • Focus tracking is updated in UpdateControlRotation every tick. In networked games, this affects control rotation on the server — verify the pawn's rotation replication settings so clients see the correct rotation.
  • Passing nullptr does not clear the focus slot — use ClearFocus() instead. Passing nullptr leaves the slot in an inconsistent state that can produce unexpected pawn rotations.

Signature

virtual void SetFocus(AActor* NewFocus, EAIFocusPriority::Type InPriority = EAIFocusPriority::Gameplay);

Parameters

Name Type Description Default
NewFocus AActor* The actor to track as the AI's focus target.
InPriority EAIFocusPriority::Type Priority slot for this focus. Defaults to Gameplay priority. EAIFocusPriority::Gameplay

Return Type

void

Example

Lock AI gaze onto an enemy C++
void AMyAIController::OnEnemySpotted(AActor* Enemy)
{
	SetFocus(Enemy, EAIFocusPriority::Gameplay);
	// Pawn will now rotate to face Enemy every tick
}

Version History

Introduced in: 4.8

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.