Hi there, I’m currently working on a project for my video game design class where I’m supposed to turn the “Puzzle” template into TicTacToe. I was wondering, how would I store a variable in the PlayerController class, specifically a boolean, and use it in the Block class in order to trigger if statements? I have tried looking online but have come up only empty handed and farther away then I was to begin.
Without having looked at the Puzzle template… I’d do something quick and dirty like this:
Declare your bool variable in the your player controller’s .h file
// some bool
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Bools)
bool bSomeBool;
Then inside your block class header, you’d would declare a pointer variable to store a reference to the player controller.
// Player Controller Reference
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Controller)
APlayerController* PlayerController;
Then inside the Block’s BeginPlay function (or wherever is convenient) you’d collect and store a reference to the current player controller. Below is just one of the many different ways to accomplish this.
PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
Finally, you could then set the bool accordingly somewhere else in the Block class by using the pointer
// Always check to ensure the pointer is valid
if (PlayerController)
{
PlayerController->bSomeBool = true;
}
Quick and dirty, but easy enough!