How to get a reference to AAIController ?

Hello,

I need to get a reference to AAIController from character class, and when obtain the location of my bot after pressing the key. How to do it right ? I unsuccessfully tried to do this by using these methods:

Thanks!

ABotAIController* BotAI = Cast<ABotAIController>(ABotAIController::StaticClass());

ABotAIController* BotAI = NewObject<ABotAIController>(this, ABotAIController::StaticClass());

ABotAIController* BotAI = ABotAIController::StaticClass()->GetDefaultObject<ABotAIController>();

ABotAIController* BotAI = ()->SpawnActor<ABotAIController>(ABotAIController::StaticClass());

UClass* BotAI = ABotAIController::StaticClass()->GetClass();

AAIController is a AController same as APlayerController, which means it posses pawns same as player controller. So you spawn controller with SpawnActor and posses any Pawn and now AIController is accessable from pawn via GetController() and pawn from controller via GetPawn().

You can’t get a static reference to an AIController class because it needs to possess a pawn in order for it to be meaningful. Usually you would set a character placed in a level (or a character blueprint) to use your controller class from within the editor, but it really depends on how you’re creating your bots. After you have a pawn set to be controlled by your controller, you can use .GetController() as pointed out or the equivalent blueprint node if you’d rather.

For more info on controllers and AI, you might want to hit-up these links: How do I assign an AI Controller to a Pawn? - AI - Epic Developer Community Forums and https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/QuickStart/6/index.html

Just to reiterate, static AIControllers don’t make sense. AIControllers must posses pawns.