How do I get the AI controller from an actor?

I’ve been attempting to make an RTS using pure Blueprint, and I read on AnswerHub that the best approach to create an unit would be to create an AIController, in my example named RTSPawnController, assign this as the AI Controller for my Character (or Unit. I use the Character class for different units like Warrior, Archer, Mage, etc.), and then control these AI controllers with a global PlayerController.

First of all I’d like to know if this is the correct approach. Should I use characters for units? Should I use AI Controllers for units? Should I manage these AI controllers from a PlayerController?

Second of all, how would I get the AI Controller off of a character? I have created a function in my AI Controller called AI_MoveToPoint, and I would like to call this function for all the selected characters from my PlayerController Blueprint.

NOTE: This question is now solved. The answer is found in the comments of the accepted question.

You could check out this template:

It’s really awesome and helped me a lot to get started :wink:

Thank you, but I’ve read through the blueprints and it unfortunately doesn’t answer my question.

Well it does have the working Unit movement.

Anyway to directly answer your question: The node “Get Owner” should be what you are looking for.

Thank you for the quick reply. Here’s what I’m currently doing:


The cast, however, fails. I’ve assigned BP_RTSPawnController as the AI Controller in the character as follows:


Why would the cast fail?

Could you print the displayname of the result of “Get Owner” real quick for me?

The display name is empty

If I firstly cast to BP_BaseUnit, and then do the Get Owner, they owner is still empty however the display name is now displaying correctly.

It works now!

Solution:

First of all, I get all actors that have my BaseUnit class. Then I For Each through them, and cast each one to my BaseUnit class. From that point I can do a ‘GetController’, and cast the controller to my controller class. BP_RTSPawnController. At this point the cast was successful and I can call my controller’s move function.

I will mark your answer as correct.