How can I apply damage using Collision Overlap?

Hey! I am trying to create a simple damage script using collision overlap. What I am trying to do exactly is that I call a function on "OtherActor"s Script called “ApplyDamage” and send the damage that the projectile should do to the player. Anyone know how I would do this?

Here is what I am using at the moment.

void ACollectable::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
	{
		if (OtherActor->IsA(AFPSCharacter::StaticClass())) //check if a player was hit
		{
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, "Collision with health object!");
			OtherComp->ApplyDamage(Damage); //obviously this does not work, but maybe something along those lines?
			MeshComp->DestroyComponent();
		}
	}
}

Thank you in advance!

Wow, did not expect this to be so difficult (pretty easy to do in Unity). Nobody have any ideas? Should I try something else?

You could call AActor::TakeDamage and override the function in your character class.

Okay so the method I used to make this work was casting:

void ACollectable::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
	{
		if (OtherActor->IsA(AFPSCharacter::StaticClass()))
		{
			GiveDamage(Cast<AFPSCharacter>(OtherActor)); //cast to "OtherActors" FPSCharacter Class
			GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, "Collision with the collectable!");
			MeshComp->DestroyComponent();
		}
	}
}

void ACollectable::GiveDamage(class AFPSCharacter* pl)
{
if (pl)
	{
	pl->Health -= Damage;
	}
}

I ended up doing something different, but how does “TakeDamage” actually work? Do you have to define your health variable in it or something? Always confused me a lot…anyway, thanks for your reply! +1 This is probably a pretty good solution to the problem as well