How do you give AI players a PlayerState?

I would like to add bot players to my game. Spawning an AIController and making it possess a pawn is not a problem, but how do you give it a PlayerState?

There is no way to set a controller’s player state, and if you spawn an AIController, it won’t get any. Without a player state, bots are practically useless - I want them to have scores, names etc. like normal players.

I would have expected that there was something like CreatePlayer just for bots, but it appears that there is no out-of-the-box handling for bots whatsoever. Or, at least, none of it is exposed to Blueprint (e.g. InitPlayerState is not).

How can I get proper bot players to work using Blueprint?

I am also pretty keen on understanding the same. Any help on this would be great ?

I too would be interested in knowing how to do this as well. Anyone done this before?

I haven’t tried this myself yet (just about to try it now!), but this post seems to have the answer to this. It looks as though you can’t do it from blueprints, but there is a c++ variable that can be set to give AI’s PlayerStates.

It’s still a request!

why tho? all your bots are pawns that can have variables like scores etc. You should use a Servers PlayerState to handle all bot scores and stuff.

Because pawn are not supposed to store anything like scores. Pawns get destroyed, the controllers don’t. Player states made for containing these informations. And we would like to make AI players just by swapping out the controllers.

1 Like

I managed to get PlayerState to AI successfully. First, you can’t get PlayerState for AI in Blueprint, you have to do it c++ way. Convert your project to c++ project if needed. Then create new c++ class with name “MyAIController” (name it what ever you like).

In your MyAIController.cpp write:

#include "AMyAIController.h"

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

In your MyAIController.h write:

#pragma once

#include "CoreMinimal.h"
#include "AIController.h"
#include "AMyAIController.generated.h"

/**
 * 
 */
UCLASS()
class PROJECTNAME_API AMyAIController: public AAIController
{
	GENERATED_BODY()
	
	
public:
	AMyAIController(const FObjectInitializer& ObjectInitializer);
	
};

And that kind of is it. You can now extend this class in your editor with a blueprint and default PlayerState is added to your AI Controller

I didn’t come up with this solution, I just concatenated data to here.
Credits to users @Sam_the_Anon9 , @anonymous_user_f5a50610, @paradoc, @Tim C

1 Like

I’m using 4.17 and doing what Ollinator does here works: Hot to make a Playerstate for AIController - Character & Animation - Unreal Engine Forums

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

how to though thanks

Create a BP subclass of aicontroller, change properties:

273941-aicontroller-player-state.jpg

3 Likes

Thanks mate!

I’m on 4.27, this doesn’t seem to exist anymore. Any idea where I can find this?

Edit: Finally found it, click on Class Defaults first. I thought it was in class settings.