TakeDamage and health

I was following the multiplayer tutorial and trying to have the player take damage.

So I added this in my PlayerController.h:



UFUNCTION()
float TakeDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser);


in my cpp file:



void AWhyMePlayerController::BeginPlay()
{
Super::BeginPlay();

GetOwner()->OnTakeAnyDamage.AddDynamic(this, &AWhyMePlayerController::TakeDamage);
}




float AWhyMePlayerController::TakeDamage(AActor* DamagedActor, float Damage, const class UDamageType* DamageType, class AController* InstigatedBy, AActor* DamageCauser)
{
float damageApplied = _currentHealth - Damage;
SetCurrentHealth(damageApplied);

return damageApplied;
}

When I try to build I get the following compile error: No instance of function template
However, I copied the function declaration from AActor

I may be wrong, but as far as I remember, the damage is taken by the pawn and not the controller. You can override TakeDamage function in your pawn.



UFUNCTION() virtual float TakeDamage(float DamageAmount, struct FDamageEvent const & DamageEvent, AController * EventInstigator, AActor * DamageCauser) override;


Yea, I had the wrong function deceleration