UGameplayStatics::GetPlayerController(this, 0) VS GetTankPlayerController()

Question regarding the getting player controller in ToonTanksGameMode.cpp. Is there a reason we are not using

Tank->DisableInput(UGameplayStatics::GetPlayerController(this, 0));

instead of making a getter for a private APlayerController in tank class and using that to disable input?

Would it provide the same result?

You don’t actually need either. You can simply pass in this or even nullptr. This is the code for DisableInput

void APawn::DisableInput(class APlayerController* PlayerController)
{
	if (PlayerController == Controller || PlayerController == nullptr)
	{
		bInputEnabled = false;
	}
	else
	{
		UE_LOG(LogPawn, Error, TEXT("DisableInput can only be specified on a Pawn for its Controller"));
	}
}

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms