Examples
The following scenarios demonstrate how the Damage System (DS), Armor System (AS) and Projectile System (PDS) work together in a typical game.
1. Damage + Armor Mitigation (C++ & Blueprint)
This setup shows a character taking damage that is first routed through armor. The core flow is:
- Projectile populates an
FDamageContext
and callsProcessDamageEvent()
on the target'sUDamageRouterComponent
. - The router invokes
UArmorSystemComponent::ProcessDamageInteraction()
for mitigation. - Remaining damage is applied to the
ULimbSystemComponent
/UCharacterAttributeSet
.
The sequence shows:
- The player projectile hits the target.
- The target routes the hit to the Damage System.
- The Damage System consults the Armor System to reduce damage.
- Finally, the Limb Health System applies the remaining damage and effects.
C++ Component
CPP
// MyCharacter.cpp
void AMyCharacter::BeginPlay()
{
Super::BeginPlay();
DamageRouter = FindComponentByClass<UDamageRouterComponent>();
ArmorSystem = FindComponentByClass<UArmorSystemComponent>();
}
void AMyCharacter::ReceiveProjectileHit(const FDamageContext& InCtx)
{
FDamageContext Context = InCtx;
DamageRouter->ProcessDamageEvent(Context);
}
Blueprint Flow
- Create a Custom Event
OnHitByProjectile
taking anFDamageContext
input. - Call the above C++ function
ReceiveProjectileHit
. - Add an Armor System Component and Damage Router Component to the Blueprint.
- The router handles mitigation and health updates automatically.
2. Spawning a Projectile in Blueprint
This example spawns a projectile actor and routes its damage through the DS.
- From your weapon Blueprint, Spawn Actor From Class using
ABaseProjectile
(or subclass). - Set its Archetype property to a
UProjectileArchetypeDataAsset
. - When the projectile impacts, it should call
ProcessDamageEvent()
on the hit actor:
CPP
// Inside ABaseProjectile::ProcessImpact()
FDamageContext Context;
Context.ProjectileMassKg = Archetype->MassKg;
Context.ProjectileRoundType = Archetype->RoundType;
Context.CurrentDamageToApply = Archetype->BaseDamageAmount;
Context.DirectDamageEffectClassToApply = Archetype->DirectDamageGameplayEffectClass;
HitActor->FindComponentByClass<UDamageRouterComponent>()
->ProcessDamageEvent(Context);
The spawned projectile automatically uses the DS enums (ERoundType
, EProjectileType
) defined in DamageSystemTypes.h
.
3. Attribute Data Table
Define a data table to initialize attributes in UCharacterAttributeSet
.
CSV
Name,Health,MaxHealth,Stamina,MaxStamina
Default,100,100,50,50
Reference the table in code when initializing stats:
CPP
// Somewhere in character initialization
AbilitySystemComponent->InitStats(
UCharacterAttributeSet::StaticClass(),
AttributeDataTable
);
This allows designers to tweak starting values without recompiling.