Do AIControllers characters have Playerstate?

I tried to spawn AI characters with “Spawn AI from Class” node. However playerstate is none when I try to access it in the character’s blueprint function. The playstate array from gamemode blueprint also only has one item, which is from the player.

https://docs.unrealengine.com/latest/INT/Gameplay/Framework/QuickReference/index.html
According to the doc, there seems have playerstate for AI characters.

Any idea? Thanks.

AI is not a player, so AIController does not create PlayerState by default. But it got mechanisms for enableing PlayerState for AI but it seem its not accesable via blueprint.

AIController got property if it want to create player controler, looking on source code it is set to false by default in constructor
https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AAIController/bWantsPlayerState/index.html

Also Controller class have funtion to init state for controller

So you need to do it in C++, it actully sould be easy, just use “Add Code to Project” (you will need to make your project C++), create class based of AIController and name it AIPlayerController (or whater you like ; p) and in created cpp file you just add bWantsPlayerState = tru;e in constructor, like this

AAIPlayerController::AAIPlayerController(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{

	bWantsPlayerState = true;

}

Compile and then create a blueprint based on that class for your AI :wink:

1 Like

Thanks for the detailed explaination. I did take a look at the header file and it’s enabled there… I didn’t expect they disabled it in the constructor… haha…

for any other ue4 c++ newbs like myself, here’s a link to the updated syntax for this stuff as of 4.6 i believe: New Syntax. So in the case mentioned above where a player state is needed, ObjectInitializer is required instead, as well as a minor modification to the header file.