Hot to make a Playerstate for AIController

It seems that the only way to give an AIController a Playerstate is by changing options within C++.
I am writing this for those who may not be familiar with C++. Please note that I am using UE4 version 4.11.1 (I believe that some of the coding is different for earlier versions, especially pre-4.6).
Here are the steps to take:

Step 1: Click “File” and select “New C++ Class” from the drop-down menu;

Step 2: In the pop-up that says “Choose Parent Class,” click the box in the top right that says “Show All Classes” and select “AIController” from the list;

Step 3: Name the class whatever you want (I chose “MyAIController_Parent”)–NOTE: I haven’t experimented with this yet, but I made the class “Public” (not sure if “Private” works, too);

Step 4: Open Visual Studio 2015 (or whatever version) and find both the .h and .cpp files for the class you created;

Step 5: In the .h file, find “GENERATED_BODY()” and add " AMyAIController_Parent(const FObjectInitializer& ObjectInitializer);" below it, as follows:

class CPP_04_08_2016_API AMyAIController_Parent : public AAIController
AMyAIController_Parent(const FObjectInitializer& ObjectInitializer);

Step 6: In the .cpp file, add the following:

AMyAIController_Parent::AMyAIController_Parent(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
bWantsPlayerState = true;

Step 7: Save, compile, and you’re done!

I hope this helps. I’ve also uploaded some screen shots

I realize that this technically wasn’t a “question,” so if it belongs in a different section, please let me know. I will mark it as “answered”

unfortunately it doesnt work. i set breakpoints into the constructor of the aicontroller, the constructor of myaicontroller and in the PostInitializeComponents function of aicontroller where the playerstate is created (if bWantsPlayerState is true). all breakpoints are hit in the above correct order, so bWantsPlayerState SHOULD be true, but for some weird reason it isnt! so the playerstate is not spawned/initialized still… :frowning:



i hacked it to work by overriding PostInitializeComponents() setting bWantsPlayerState THERE to true and then calling PostInitializeComponents of AIController.
like this:


no idea why it doesnt work setting it in the constructor…perhaps is reset somewhere else i couldnt find…regardless: my AI now has a playerstate! :slight_smile:

I’m not exactly sure why it’s not working for you. I’ve tried it with a blank project and it still works fine for me… I did notice that you set up the notify under “AAIController”. Since the parent won’t inherit from the child, it wouldn’t be changed to “true” there. Did you try setting up the notify from your “AMyAIController”? Please let me know if you still can’t get it working right.

Only correct answer out there! Thank you!!! :slight_smile:

As of UE 4.20, this is finally exposed to Blueprint, so the C++ class is no longer necessary.