I am trying to create a FPS game with bots (similar to shooter game example). I want the bots to behave just like other players, so I want them to have a player state to keep scores, names, team, etc.
Figured this one out on my own. For anyone else with this question, here is what I did (again, this is Unreal Engine 4.17):
I created a C++ class. I named it BotAIController. It’s parent class is AIController.
In the .cpp file:
#include "BotAIController.h"
// Function that sets bWantsPlayerState. bWantsPlayerState is a variable in the parent
void ABotAIController::SetWantsPlayerState(bool NewValue)
{
bWantsPlayerState = NewValue;
}
In the .h file:
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "BotAIController.generated.h"
/**
*
*/
UCLASS()
class SPECVS_MK3_API ABotAIController : public AAIController
{
GENERATED_BODY()
public:
// Sets the variable bWantsPlayerState
UFUNCTION(BlueprintCallable, Category = "PlayerState")
void SetWantsPlayerState(bool NewValue);
};
Remember, if you name your project or controller something different, you will have to make some minor changes to the code.
That’s it! It was much more simple than the code for 4.4, which, for anyone interested, looked something like this:
One thing I forgot to mention is that you also need to create a Blueprint. Right-click on your C++ class and click ‘create blueprint based on class’. Open the new blueprint, and in the construction script add the node ‘Set Wants Player State’ (the new function created in C++). Check the box called ‘NewValue’, and then it should work.