Handle different damage types

Hi,

I want to create multiple damage types (i.e normal damage, poison, slowdown, stun, fear…), but I don’t know what is the best way to do it.
I have different functions in which I have the implementation of the different damage types, but I don’t know where call them, neither how works the parameter DamageType-DamageEvent. I also read about bind delegates with OnTakeAnyDamage, but I cannot make it run.

Can someone explain what is the best way to handle that different types of damage?

thanks :slight_smile:

Hello Davixe,

DamageType it is class that used to handle type of damage that was applied to some actor. For example you can have different damage types for your weapon (simple bullets, incendiary bullets, etc.)
This function pass your damage type class to the TakeDamage function through EventDamage parameter.

// process machine gun hit function
UGameplayStatics::ApplyPointDamage(HitResult.Actor.Get(), ImpactDamage, ShootDir, HitResult, MyController.Get(), this, UDamageType_Gatling::StaticClass());

// Take damage function
float AMyPawn::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser)
{
	…
	DamageEvent.DamageTypeClass;
	…
}

Best regards,

Yeah, that makes sense, thx for the answer, but still don’t understand how can I bind a specific delegate function to execute in TakeDamage.

Thx.

Hey Davixe,

Syntax for binding delegate looks like

OnTakeAnyDamage.AddDynamic(this, &MyActor::MyTakeAnyDamage);
void MyTakeAnyDamage(float Damage, const class UDamageType DamageType, class AController InstigatedBy, AActor* DamageCauser)
{
}

TakeDamage it is not delegate, it should be overridden.

Cheers

Hi,
What I want is something like bind a function inside my projectile class, so I can have a lot of different projectiles which have different behaviour, then, execute that behaviour on the TakeDamage, so I can avoid an endless switch case inside the TakeDamage. Can i do that? or I’m asking about magic? xD

thx for the answers :slight_smile:

Hi,

Yes, for example you can create virtual function in your base projectile class and override it in derived classes to implement specific behavior.

Best regards,