ACharacter::ApplyDamageMomentum
#include "GameFramework/Character.h"
Access: public
Specifiers: virtual
Description
Applies an impulse to the character's movement component based on the incoming damage event. Typically called from TakeDamage() to produce a physics-style knockback effect.
Caveats & Gotchas
- • This does nothing by default — the base implementation is empty. You must override it and call LaunchCharacter() or AddImpulse() yourself to get actual knockback behaviour.
- • The magnitude of the impulse is not tied to DamageTaken automatically; you decide the relationship in your override. Common mistake is assuming it self-scales.
Signature
virtual void ApplyDamageMomentum(float DamageTaken, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| DamageTaken | float | Amount of damage that was applied. | — |
| DamageEvent | FDamageEvent const& | The damage event describing the hit, including hit result and damage type. | — |
| PawnInstigator | APawn* | The pawn that caused the damage. | — |
| DamageCauser | AActor* | The actor that directly caused the damage (e.g. a projectile). | — |
Return Type
void Example
Apply knockback from point damage C++
void AMyCharacter::ApplyDamageMomentum(float DamageTaken, FDamageEvent const& DamageEvent,
APawn* PawnInstigator, AActor* DamageCauser)
{
const UDamageType* DmgType = DamageEvent.DamageTypeClass
? DamageEvent.DamageTypeClass->GetDefaultObject<UDamageType>()
: GetDefault<UDamageType>();
if (GetCharacterMovement() && DmgType->DamageImpulse > 0.f)
{
FHitResult HitInfo;
FVector ImpulseDir;
DamageEvent.GetBestHitInfo(this, DamageCauser, HitInfo, ImpulseDir);
FVector Impulse = ImpulseDir * DmgType->DamageImpulse;
LaunchCharacter(Impulse, false, false);
}
} Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?