Defense

Documentation Unreal Engine Player Combat Defense Combat

Defense gives a character a guard: an ordered list of responses (parry, block, invulnerability, armor) answers each hit, and the first that fits decides the damage and tells the attacker.


Set it up

3 minutes
  1. 1

    Create a Defense Rule Set

    Content Browser
    ▸ Content
    Right-click in the Content Browser, UPC, Damage and Defense, Defense Rule Set.
  2. 2

    Author a parry and a block

    Press + on Responses twice and pick UPC Guard both times. A Guard starts out as a block, so make the first one a parry that lets nothing through and costs nothing.
    DefenseRuleSet_MySword
    ▾Responses > Index [ 0 ] (UPC Guard)
    Damage Multiplier0.2
    Required Defender Tags 
    Result Tag 
    Cost Per Damage1.0
    Listed first, so a hit inside the parry window never reaches the block.
    DefenseRuleSet_MySword
    ▾Responses > Index [ 1 ] (UPC Guard)
    Required Defender Tags 
    Result Tag 
    The rest of a Guard ships as a block: a 60 degree half-angle and a 0.2 multiplier. It charges nothing until its Cost Vital Tag names a pool.
  3. 3

    Lend the set from the item

    Open Item_MySword, add a Guard fragment to its Fragments, and point its Defense Set at the asset. The character answers hits with it while the sword is drawn.
    Details
    Guard
    Guard
    Defense Set
    DefenseRuleSet_MySword
    The block, parry or other responses the item lends whoever holds it, authored in a Defense Rule Set.
  4. 4

    Hold the tags while the guard is up

    A response answers only while the character holds its Required Defender Tags, and nothing puts them on for you. The sword's graph from First Combo has no guard move yet, so add three things (steps in A parry and a block):
    • A raise montage node, entered on UPC.Input.Guard, with a UPC State Tag Window holding UPC.State.Parrying across the parry frames.
    • A Hold node after it, its Applied Tags holding UPC.State.Blocking.
    • Input Released from both nodes back to Root.
    Map IA_UPC_Guard to UPC.Input.Guard in the Equippable fragment's Input Mappings.
  5. 5

    Play, and hit it with the guard up

    A fifth of the damage lands, and the attacker's swing comes back carrying UPC.DamageResult.Blocked. Inside the parry window nothing lands. Drop the guard and the blow lands whole.

The responses that ship

ResponseAnswers whileShips as
UPC InvulnerableThe character holds its tags, from any direction.Damage 0, no cost
UPC GuardThe character holds its tags and the blow arrives inside Arc Half Angle Degrees of the front.A block: 60 degrees, Damage Multiplier 0.2, Cost Per Damage 1
UPC Scale DamageThe character holds its tags and the attack carries its attack tags (empty passes). It scales the hit and lets the responses below run on.Damage Multiplier 1, Continue After Claim on
Each list runs top down and the first response that answers ends the walk, so order it most specific first: invulnerability, then the parry, the block and armor. Armor at the bottom answers every hit the responses above let past. A response with Continue After Claim ticked lets the ones below it run on what it let through. A 100-damage blow against a block (0.2) listed above armor (UPC Scale Damage, 0.5):
The blowLands
Inside the block's arc20: the block answers and ends the walk
Inside the arc, with the block's Continue After Claim ticked10: the armor halves the block's 20
From behind50: the block does not answer, the armor does
You wantSet
A block that costs staminaCost Vital Tag to the stamina pool. A Guard charges Cost Per Damage (1) per point of the incoming blow, plus Flat Cost: a 40-damage blow costs 40 stamina, and the block lets 8 through. A character that cannot pay falls through to the responses below, a guard break that reports no result; to tell the attacker, add a UPC Scale Damage below the guard with UPC.State.Blocking in Required Defender Tags and UPC.DamageResult.GuardBroken as its Result Tag.
Frames that take nothingUPC Invulnerable at the top with Required Defender Tags, such as the shipped UPC.State.Invulnerable. The hit still resolves and plays its impact. For a dodge, use the attacker's Pass Through Tags instead.
Armor against one kind of damageUPC Scale Damage at the bottom, the kind in Required Attack Tags (UPC.DamageType.Slash), Damage Multiplier 0.5. Empty attack tags make flat armor.
Extra damage while staggeredUPC Scale Damage with UPC.State.Staggered in Required Defender Tags and Damage Multiplier 2.
An attack a guard cannot stopUPC.Attack.Unblockable (or UPC.Attack.Unparryable) in the attack's Damage Tags and in the guard's Blocked Attack Tags. The blow falls through to what sits below.

Where the responses come from

Most situational firstA hit enters at the top
1
What the character holds
Guard fragment on each drawn item, lent through the UPC Equipment Manager
A supporting item such as a shield answers ahead of the weapon that drives the moves. A set stops answering the moment its item is put away.
2
Responses on the component
UPC Defense > Responses
The character's own answers: its dodge frames, its stance. Authored on the character, so they hold whatever it is holding.
3
The shared set
UPC Defense > Defense Set
A Defense Rule Set several characters point at. Last in the walk, so a broad resistance here trims whatever the answers above it let through.
The first response that answers the hit ends the walk. Tick Continue After Claim on a response and the ones below it keep shaving what is left, which is what armor wants and a parry does not.
The driving weapon is the drawn item whose action graph runs (Equipment). The UPC Character Base carries the UPC Defense component; a pawn of your own adds it and implements UPC Damageable (A pawn not built on the base).
Details
UPC Defense
UPC
Defense
Defense Set
DefenseRuleSet_MyArmour
Responses
0 Array elements
Outcome Effects
0 Array elements
Responses run top down. The Guard fragments of the items the character holds answer first, then these, then the Defense Set.
Sources run in that order: a drawn item's lent sets, then the component's own Responses, then its Defense Set; inside each, the list order above applies. A character with dodge frames (UPC Invulnerable) in its own Responses and a drawn shield lending a block, hit mid-dodge from the front by 100 damage, takes 20: the shield's block answers first and ends the walk. Tick the block's Continue After Claim and the walk reaches the dodge frames, which take the 20 to nothing. A character with no responses anywhere takes every hit at full damage.

Tell the attacker what happened

A response that answers adds its Result Tag to the hit's result, which the attacker reads twice: its melee trace's Skip Record Tags decide whether the swing is spent, and its hit effects can sit out or play for that outcome. Four tags ship: UPC.DamageResult.Parried, UPC.DamageResult.Blocked, UPC.DamageResult.GuardBroken and UPC.DamageResult.PoiseBroken; a tag of your own works the same, and a parent covers its children. An answer with no Result Tag reads to the attacker as a clean hit, and the log names it once.

Act on the outcome

Outcome Effects, on a Defense Rule Set or the component, are what the character does beyond taking the damage: a spark, a counter window, a stagger sent back to whoever swung. They are the hit effects a damage config carries, run once the pools have drained. A parry opening a counter window is one row:
SettingValue
EffectUPC Apply Gameplay Effect
Require Any Result TagsUPC.DamageResult.Parried
Gameplay EffectA timed gameplay effect holding the window, such as the demo's GE_UPC_CounterWindow, which grants UPC.State.CanCounter
Affected SidesTarget
Every effect that passes its gates runs. Tick Outcome Effects On Own Answer Only on a set to run its effects only on hits its own responses answered, so a sword's block sound stays quiet while the shield beside it takes the blow.

Debug it

LogUPCDefense names a response charging a vital the character has no pool for, a response answering without a Result Tag, a character with no health pool, and an attack listing health in its Additional Vital Damage. LogUPCDamage warns as a UPC Character Base begins play with no Vitals row for its Health Vital Tag. Preview Incoming Damage on the component gives a real hit's answer and charges nothing, for a debug widget or a guard meter.
AdvancedFields every response carries
FieldSets
Required Defender Tags, Blocked Defender TagsTags the character must all hold, or must hold none of, for this to answer.
Result TagThe name reported to the attacker. Unset suits armor that only shaves damage.
Required Attack Tags, Blocked Attack TagsTags the attack's Damage Tags must all carry, or carry none of. A parent tag covers its children.
Continue After ClaimLet the responses below keep scaling what this one let through. Off on Guard and Invulnerable, on for Scale Damage.
Cost Vital Tag, Flat Cost, Cost Per DamageThe pool this answer charges and how much: flat per hit plus per point of the blow before any reduction. With no tag the answer is free and needs no vitals.
Spend Remainder when UnaffordableEmpty the pool on the blow it cannot afford, raising its depleted tag and event, for a guard that breaks. The hit falls through either way.
Vital Damage MultipliersA rate of its own for one vital, such as stance passing at full while a block halves health. Empty applies the response's multiplier to every vital.
  • A Guard's Arc Half Angle Degrees at 180 accepts every direction, and a blow with no direction counts as frontal. UPC Invulnerable with no tags takes every hit.
  • Two responses charging one pool are measured against a running total, so a pool that covers one does not cover both.
  • A character with a costed response and no UPC Vitals answers for free, and the log names it once.
  • UPC Scale Damage reports no result tag unless given one.
AdvancedA pawn not built on the base
Implement UPC Damageable and fill Handle Incoming Damage with Resolve Defense and Apply Damage, as Character Setup shows. The node runs the responses, takes what survived off the pools (health first, then each other vital, then the costs), runs the outcome effects and reports Was Fatal.
BP_MyPawn · UPC Damageable interface
Handle Incoming Damage
Damage Info
Defense
Resolve Defense and Apply Damage
Target is UPC Defense Statics
Defense
Damage Info
Health Vital TagUPC.Vital.Health
Return Value
Return Node
Return Value
Wire the UPC Defense component into Defense; empty, the hit lands at full value. Set Health Vital Tag to UPC.Vital.Health and give the pawn a UPC Vitals row for it; without either, the node resolves the hit and drains nothing.
AlternativeYour own damage path
  • Resolve Defense and Apply Damage (Any Damage Event) takes Unreal's loose damage numbers and works the blow's direction out from where the attacker stands. It drains health too. Prefer the plain node wherever a damage info exists, since it carries the attack's tags.
  • Resolve Incoming Damage on the component runs the responses and charges costs but drains nothing: subtract its Damage Applied from your own health and return the result unchanged, so the attacker still gets the tags.
AdvancedExtending the defense
  • A response of your own: subclass UPC Defense Response in Blueprint. It gets the defender gates, attack gates, cost and Result Tag fields, checked and reported for it. Should Apply judges whether it handles the hit and changes nothing; Apply scales or zeroes Final Damage, once Should Apply agreed and the cost was affordable. UPC Defense Rule, its C++-only base, checks its own tags in Should Apply and adds its own result tag in Apply.
  • Responses from somewhere else: implement UPC Defense Set Provider on the pawn or any of its components and return the sets in force from Get Defense Sets; the UPC Equipment Manager answers it with the drawn items' Guard sets. The component asks on each hit and stores nothing. Override Get Effective Responses to build the list another way.
  • Your own resources: override Can Afford Response Cost, which must change nothing, and Pay Response Cost together, plus Get Payable Response Cost for Spend Remainder when Unaffordable. A pawn keeping its states elsewhere overrides Get State Tags.
The demo
Item_UPC_Sword lends DefenseRuleSet_UPC_Sword (a parry, a block and the counter window row above), Item_UPC_TwoHandedBaton the same shape in DefenseRuleSet_UPC_TwoHanded, Item_UPC_Shield a block in DefenseRuleSet_UPC_Shield; sword and shield sets play outcome effects on their own answers only. DefenseRuleSet_UPC_Character is the characters' own set: poise, hyper armor and the boss's finisher (Hit Reactions).
MultiplayerMultiplayer
Run Resolve Defense and Apply Damage on the server: a call elsewhere charges and drains nothing, and its result is advisory. Preview Incoming Damage gives the same answer on any machine. Vitals replicate on their own.
AdvancedTroubleshooting
The character is hit and nothing changes
In the order worth checking:
  • Nothing holds the tag. No ability, node or window holds the response's Required Defender Tags. The common cause, and it logs nothing.
  • No Handle Incoming Damage. A pawn without UPC Damageable takes Unreal's point damage and its Defense component never runs. The UPC Character Base implements it.
  • Can be Damaged is off. The character takes nothing and no response runs.
  • The blow came from outside the arc. A Guard measures against the character's real facing; a hit from behind falls through.
  • An attack tag turns it away. A tag in Blocked Attack Tags lets the blow past; a Required Attack Tags entry the attack lacks keeps it silent.
  • A response above it answered. The first answer ends the walk unless it has Continue After Claim ticked.