x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Feb 04 '15 at 09:06 PM in Blueprint Scripting

avatar image

pdinklag
123 6 8 12

avatar image wilberolive Nov 11 '15 at 09:23 AM

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

avatar image CrimsonHawk Nov 14 '16 at 11:34 PM

It's still a request!

avatar image Holybreath Nov 16 '16 at 04:36 PM

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.

avatar image CrimsonHawk Nov 16 '16 at 05:09 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

5 answers: sort voted first

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

more ▼

answered Jun 17 '15 at 06:55 AM

avatar image

kinzua01
21 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Jan 04 '16 at 12:12 AM

avatar image

Sam_the_Anon9
11 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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

more ▼

answered Jul 06 '18 at 10:19 PM

avatar image

lotodore
216 9 16 22

avatar image Groliver7 Apr 11 '19 at 07:20 PM

how to though thanks

avatar image lotodore Apr 11 '19 at 07:46 PM

Create a BP subclass of aicontroller, change properties: aicontroller_player_state

avatar image Groliver7 Apr 11 '19 at 08:11 PM

Thanks mate!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 , @Shadowriver, @paradoc, @Tim C

more ▼

answered Jan 23 '18 at 09:00 AM

avatar image

FinalZer0
126 2 7 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
more ▼

answered Jan 24 '18 at 12:39 PM

avatar image

JohnnyDale
36 1 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question