AI Controller and Player State

I would like to add bots to my game that are controller using an AI Controller, which I have set up now. However, I would like the bots to be treated like regular players in the game, i.e. they should have a name, score, etc… and show up on the scoreboard just like a real player does. However, AI Controllers don’t have Player States. Therefore they don’t have this kind of data and are not replicated to the clients at all, so I don’t know how to go about doing this. Any advice?

You need to add a widget for the name (just a hud widget with some text field), which you then attach on the AI BPs EvenBeginPlay. You could track the score via your GameInstance or level blueprint, a float or integer value which is updated when the AI scores. Also this would require a widget, but this attached to the player view, thus loaded/attached to the player character on EventBeginPlay.

There are many examples for Player HUD in Unreal.

Sorry, I’m actually not worried bout the HUD and widgets. I’ve already got all that sorted, with a scoreboard and such that each player can view. The issue is that in a multiplayer game with say 2 real players and 2 AI players, when you press tab to view the scoreboard, you only see the two real players listed because only real players have a Player State. In addition, the Player Array in the Game State, only tracks real players with Player States. Therefore, AI players are not treated like real players. They don’t have a Player State and they are not added to the Player Array in the Game State. I’m trying to think of a way around this, so that the AI players are treated like real players in the game, so they can have a player state (of sorts) and they do show up in the scoreboard like a real player. I’m just not sure what is the best way to go about it and was hoping someone else might have done this before and have some advice?

Sorry for posting in an old topic, but for new users, if you need the player state for your AI characters all you need to do is just set


 bWantsPlayerState = true;

in your AI Controller class.

2 Likes

Thanks, good hint!

In case someone also searches for this, you can look here for a more detailed answer how to implement this:
https://answers.unrealengine.com/que…uctinitia.html