Accessing AIController From Actor Component

Good Evening All,

I am working on creating a utility AI setup and the framework is mostly complete. Now I am looking to do some testing and I running into a problem that seems very silly.

So I have a c++ Character class called FriendlyNPC and right now there is nothing in it but a Skeletal mesh component. I created a BP off of it and added the mannequin mesh to it.

Also set the AI Controller Class in the editor to AIController.

Then I added my AI brain component (which is the core component of my Utility AI and used an actor component for that).

Now where I am running into my issue is for the life of my I can not get the AIBrainComponent to access the AIController… Essentially I want to be able to call the MoveTo() function and have the AI feed it coordinates based off criteria for testing.

This seems like a very basic question but I am just not familiar enough with Unreal to figure out what the heck I am doing wrong. Its got to be something simple and stupid I am missing. Any Suggestions or insight would be appreciated.


What about something like this:

AIController* MyController = Cast<AIController>(GetOwner()->GetController());

Thank you for replying. That was what I was thinking. However, I get an error “class “AActor” has no member “Get Controller””.

GetOwner() is successfull however the GetController function is not. I can use GetInstigatingController() but not strait GetController();

I am guessing this has something to do with not having access to the pawn somehow. I am just not sure how to resolve it. So somehow mabye go ActorComponent → Actor → Pawn → GetController?>

I’m currently working on AI system too and this is what I do. Actor class do not have controller, so it has to be a Pawn at least. You need to cast Pawn and then access to the controller.

APawn* Pawn = Cast<APawn>(ActorComponent->GetOwner())

if (IsValid(Pawn))
AAIController MyAIController = Cast<AAIController>(Pawn->GetController())

Well hey that seemed to have worked. Thank you.

So in the short summary in the .h file I have

	APawn* Pawn;

	AAIController* MyAIController;

and then in the .cpp file I have.

Pawn = Cast<APawn>(GetOwner());

MyAIController = Cast<AAIController>(Pawn->GetController());

I am at a conference for another day and can not really test it I am home but I will update the post when I do in case anyone else has the same issue in the future.

1 Like