How to create and use DamageType?

Hallo, i’m learning UnrealEngin and C++.

Unreal has a TakeDamage function:

TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser) 

I understand the argument DamageEvent contains the type and properties of the damage. How to create such FireDamage and then use it in a function TakeDamage to describe the reaction to it?

For example:
I have turret with BP

And player with C++

float ArooMazeCharacter::TakeDamage(float DamageAmount, struct FDamageEvent const& DamageEvent, class AController* EventInstigator, class AActor* DamageCauser) 
{
	PlayerHealth -= DamageAmount;
	GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "OI HULERA OPYAT " + FString::SanitizeFloat(DamageAmount));
	if (DamageEvent == FireDamage) // !!!Here is my problem, i dont know how to achieve something like that
	{
		IgnitePlayer(DamageEvent.burningTime); // !!! I dont know how to achieve something like that too
	}

	return 1;
}

How can i get type of damage, and how can i get variables (like burningTime) from DamageType class?

Thx.

And sorry for my English, it’s not my ordinary language

In my project DamageType, is used to know what weapon deal damage to you, and what force feedback you want to give for you controller vibration or force apply to character when it hit. I mean you can put a lot of extra specific info inside that DamageType if you want more information for whatever hit you. If don’t have it will not affect anything at all.

I don’t understand how to create it, and how to get info from it

This one here is from ShooterGame example

UCLASS(const, Blueprintable, BlueprintType)
class UShooterDamageType : public UDamageType
{
	GENERATED_UCLASS_BODY()

	/** icon displayed in death messages log when killed with this weapon */
	UPROPERTY(EditDefaultsOnly, Category=HUD)
	FCanvasIcon KillIcon;

	/** force feedback effect to play on a player hit by this damage type */
	UPROPERTY(EditDefaultsOnly, Category=Effects)
	UForceFeedbackEffect *HitForceFeedback;

	/** force feedback effect to play on a player killed by this damage type */
	UPROPERTY(EditDefaultsOnly, Category=Effects)
	UForceFeedbackEffect *KilledForceFeedback;
};

In the editor, you can create blueprint from this and then set it in the apply damage, then in TakeDamage of Character who receive damage u need to do this

UShooterDamageType *DamageType = Cast<UShooterDamageType>(DamageEvent.DamageTypeClass->GetDefaultObject());

then u can use any para in that class if u want.

2 Likes

Thank you!
I understand how to use it!