What's the difference between ApplyDamage() and TakeDamage()?

In the course we use this from UGameplayStatics:

		UGameplayStatics::ApplyDamage(
			OtherActor,				// Actor that will be damaged.
			Damage,					// Damage amount.
			InstigatorController,	// Which player instigated it.
			this,					// What actor caused the damage.
			DamageType				// Type of damage done.
			);

but I stumbled on “TakeDamage()” when seeing if there was anything specific to OtherActor.

		FDamageEvent DamageEvent;
		OtherActor->TakeDamage(
			Damage,					// Damage amount.
			OUT DamageEvent,		// Data package to describe the damage.
			InstigatorController,	// Which player instigated it.
			this					// What actor caused the damage.
			);

I see the main difference (I think) is ApplyDamage() allows you to specify the DamageType, whereas the AActor’s TakeDamage() provides you with a DamageEvent type that seems to contain or let you set the DamageType along with other info.

In game development, are there examples of why use one over the other?

Would we be able to use TakeDamage() over ApplyDamage() in our project’s case, or does it matter?

You’ve basically described the difference. The GameplayStatics version creates a base damage event for you using the damage type. i.e. the two pieces of code should be the same (the damage type set in blueprint is UDamageType)

UGameplayStatics::ApplyDamage(OtherActor, Damage, MyOwner->GetInstigatorController(), this, DamageType);

// The following should be equivalent to the above
if (OtherActor && (Damage != 0.f))
{
    FDamageEvent Event(UDamageType::StaticClass());
    OtherActor->TakeDamage(Damage, Event, MyOwner->GetInstigatorController(), this);
}
1 Like

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

Privacy & Terms