AIController :: SetFocus Usually we use it and under what circumstances?

void AShooterAIController::SetEnemy(class APawn* InPawn)
{
if (BlackboardComp)
{
BlackboardComp->SetValue(EnemyKeyID, InPawn);
SetFocus(InPawn);
}
}

class AShooterCharacter* AShooterAIController::GetEnemy() const
{
	if (BlackboardComp)
	{
		return Cast(BlackboardComp->GetValue(EnemyKeyID));
	}

	return NULL;
}

Reference to the shooterGame there are some questions:

Enemy destroyed will not become illegal pointer?

AIController :: SetFocus Usually we use it and under what circumstances?

1 Like

Object type blackboard keys are storing data with FWeakObjectPtr. If enemy gets destroyed and pointer is not longer valid, reading value from blackboard will simply return nullptr value.

AIController.SetFocus is used to keep AI controlled pawn rotated towards given actor or point in space. There are a few priorities of focus points, allowing easy creation of e.g. scripted overrides. For example:

  1. AI is moving and path following automatically sets intermediate destination as focal point with low priority (EAIFocusPriority::Move). AI’s pawn is facing forward as it moves around.
  2. AI receives a target and sets it as focal point with higher priority (EAIFocusPriority::Gameplay). Pawn starts facing toward target as it keeps moving.
  3. Level script forces AI to look at specific point, setting it as even higher priority (EAIFocusPriority::LastFocusPriority + 1, usually defined by project as something more readable…). Pawn rotates toward this point.
  4. Movement stops, pawn still looks at whatever script told it to.
  5. Script clears forced focus point, pawn rotate towards most important focal point, which is right now target.
  6. Target is cleared, pawn keeps current rotation since there’s no focal points to look at.
1 Like