APawn::TakeDamage
#include "GameFramework/Pawn.h"
Access: public
Specifiers: virtualoverride
Description
Processes incoming damage on the pawn. Returns the actual damage applied after any modifications. APawn's override calls ShouldTakeDamage() before delegating to the parent, and updates the LastHitBy controller reference.
Caveats & Gotchas
- • Damage application is authoritative — in a networked game this function only meaningfully executes on the server. Health deduction should happen here or in a server-authoritative component, then replicate the result to clients.
- • Always call Super::TakeDamage() unless you are completely replacing the damage pipeline. The APawn super sets LastHitBy, which other systems (AI fleeing, hit reactions) rely on.
Signature
virtual float TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) override; Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| Damage | float | The raw damage amount requested. | — |
| DamageEvent | struct FDamageEvent const& | Describes the damage type and delivery (point, radial, or generic). | — |
| EventInstigator | AController* | The controller responsible for causing the damage. | — |
| DamageCauser | AActor* | The actor that directly inflicted the damage (projectile, explosion actor, etc.). | — |
Return Type
float Example
Override to deduct health and trigger death C++
float AMyPawn::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
{
const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
if (ActualDamage > 0.0f)
{
Health -= ActualDamage;
if (Health <= 0.0f)
{
Die(EventInstigator);
}
}
return ActualDamage;
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?