How do I make a playerstate for AIController on 4.12?

I’ve found references to adding a player state in 4.11 in the following link Hot to make a Playerstate for AIController - Character & Animation - Unreal Engine Forums

but it does not work for 4.12. Could somebody please post the solution using 4.12?

There is actually no reason to use the built-in playerstate for an AI controller as an AI controller will only ever exist on the server whereas player controllers live on the server and their owning client which is why the playerstate even exists: So that other clients can still receive information about a player without having a reference to their controller.

If you want your controller to have a player state like structure you can just create your own UObject and create a new instance of it in the BeginPlay function of your custom AI controller. From then on you can just take this object as the AI’s player state.

What exactly are you trying to achieve by giving an AI controller a player state?

I’m using a heavily modified version of Generic Shooter and I’m trying to set the which team the Bot is playing on. Generic Shooter uses the playerstate, which is way I also want to use the playerstate.

Schadek, the problem is that an AIController only exists on the server (ref: https://answers.unrealengine.com/questions/237668/is-a-client-aware-of-existing-ai-controller.html). Therefore if you want for instance to create a companion (bot) and display its statistics (as if it was a player), you simply can’t since you don’t have access to the AIController on the client side.

Sure, you could store those stats inside the Pawn in a dedicated UObject or FStructure, but:

  1. unless you also use that specific structure for a player, it’s simply adding useless data and complexity to a player pawn
  2. more importantly, when the pawn is destroyed, you lose all the information it contains, so it is not a convenient way to store stats, that’s why we use PlayerStates

In other words, I do understand the question & need of gregorjk and others on the matter (there are several threads on the subject, example: https://answers.unrealengine.com/questions/168533/how-can-i-have-proper-bot-players-with-a-playersta.html).

However, in a game with multiple character/pawn controlled by AI, it would not make much sense either to have a PlayerState for each of them (think of the minions in Paragon for instance, you don’t care about their statistics). In other term, I would create both:

  • a basic AIController (not a companion and does not appear on ladder) without PlayerState, and
  • a “companion” AIController with a PlayerState, so I can treat him like a Player and see how it evolves with me in the game

Works on 4.12

AYourAiController::AYourAiController(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
    bWantsPlayerState = true;
}

Ollinator does it correctly in: Hot to make a Playerstate for AIController - Character & Animation - Unreal Engine Forums