Associating a pawn with a player controller

You would reference the same way that you would in Blueprints, which means using the GetPlayerController function which is located in the UGameplayStatics function library.

To include UGameplayStatics, add this to your includes:

#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"

To use the GetPlayerController function, you’d use this syntax:

ACustomPlayerController* MyController = UGameplayStatics::GetPlayerController(this, 0);

If you expect that there may be different types of PlayerControllers, you could cast instead to be safe:

ACustomPlayerController* MyController = Cast<ACustomPlayerController>(UGameplayStatics::GetPlayerController(this, 0));

if(MyController)
{
    *logic here*
}

If the cast fails, MyController will be left with a null value which will cause the If statement to fail as well, avoiding any mistakes in the case of getting a playercontroller of a different class.