RealDocs

APawn::AIControllerClass

property Engine Blueprint Since 4.0
#include "GameFramework/Pawn.h"
Access: public Specifiers: UPROPERTYEditAnywhereBlueprintReadWrite

Description

The controller class to instantiate when this pawn is automatically possessed by AI. Set this to your custom AIController subclass in the pawn's constructor to give the NPC its own decision-making logic.

Caveats & Gotchas

  • Setting this to a PlayerController subclass is technically valid C++ but will cause undefined behaviour — only AIController or its subclasses should be used here.
  • Changing this property at runtime after the pawn is already possessed has no effect; the already-spawned controller continues to run. Call SpawnDefaultController() after updating the class if you need a new controller mid-play.

Signature

TSubclassOf<AController> AIControllerClass

Examples

Assign a custom AI controller class at construction time Blueprint
User Construction Script Get Game Instance Return Value Cast To MyGameInstance Object Cast Failed As My Game Instance As My Game Instance Set AI Controller Class AI Controller Class BP_MyAIController BP_MyAIController AI Controller Class
Edit Blueprint graph Assign a custom AI controller class at construction time
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
Assign a custom AI controller in the pawn constructor C++
AMyEnemy::AMyEnemy()
{
	AIControllerClass = AMyEnemyAIController::StaticClass();
	AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;
}

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.