How to EnableInput() Through code? how to reference the PlayerController?


This function requires reference to Player Controller. In BP you have a node for getting current PlayerController. How do I do the same thing in code? and why do I even need to reference a PlayerController to enable input? I just want to program some input.

I Found the answer on some vague forum thread.

first you define a BeginPlay(), why is it virtual for I dont know.

virtual void BeginPlay() override;

then you EnableInput() and they way to get the PlayerController is to say GetWorld()->GetFirstPlayerController() and that gets you the Controller.

void AAIBot::BeginPlay()

	if (GEngine)
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));


DO NOT, ever try to do this in the constructor or else Unreal 4 will crash and your project will be lost forever.