Defense System

Documentation Unreal Engine AI Defense Combat

Give a pawn a guard: create a Defense Rule Set, author one response, and an incoming hit is parried, blocked or ignored before it reaches health.


A pawn carries an ordered list of answers to an incoming hit. The first one that fits decides what the blow was worth and reports back, so the attacker can tell a parry from a block.

Set it up

60 seconds
  1. 1

    Add the Defense component

    Select the pawn, Add Component, SEC Defense. An enemy built on EnemyCharacterBase already carries one named Defense; select that instead of adding a second.
  2. 2

    Create a Defense Rule Set

    Right-click in the Content Browser, SEC, Damage and Defense, Defense Rule Set.
    Content Browser
    ▸ Content
    Right-click in the Content Browser, SEC, Damage and Defense, Defense Rule Set.
  3. 3

    Author one response

    On the asset, press + on Responses and pick SEC Guard. Set Required Defender Tags to the tag the guard holds while it is up, and Result Tag to SEC.Defense.Block so the attacker learns what happened.
    DA_Defense_KnightArmour
    ▾SEC Guard
    Required Defender Tags 
    Result Tag 
    Required Defender Tags and Result Tag both ship empty, so they are the two to fill in. The rest of a Guard ships as a block: a 60 degree arc and a 0.2 multiplier.
  4. 4

    Point the Defense component at it

    Select the pawn's SEC Defense component and set Defense Set to the asset.
    SEC Defense
    ▾SEC
    ▾Defense
    Defense Set
    None▾
    Defense Set answers after everything authored directly on the component, which ships empty.
  5. 5

    Answer Handle Incoming Damage

    In the pawn's Class Settings, add the SEC Damageable interface, then implement Handle Incoming Damage with one node. Resolve Defense and Apply Damage runs the responses, charges what they cost, takes what survived off the pawn's health pool, and reports back.
    BP_PlayerCharacter · SEC Damageable interface
    Handle Incoming Damage
    Damage Info
    Defense
    Resolve Defense and Apply Damage
    Target is SEC Defense Statics
    Defense
    Damage Info
    Health Vital TagSEC.Vital.Health
    Return Value
    Return Node
    Return Value
    Set Health Vital Tag on the node to the pawn's health pool, SEC.Vital.Health in the tags the plugin ships. The pin starts empty, and the pawn needs a SEC Vitals component carrying a row for that tag; without either one the node resolves the hit and drains nothing. See Vitals.
    Enemies built on EnemyCharacterBase answer this already, so skip this step there.
  6. 6

    Play, and hit it while the tag is held

    A fifth of the damage lands, and the swing comes back carrying SEC.Defense.Block. Drop the tag and the same blow lands whole.
A response answers only while the pawn holds the tags in its Required Defender Tags, and nothing in the plugin puts them there. A guard ability, a reaction, or a montage window has to hold one while the guard is up. Until something does, the response sits inert and hits land at full damage.
A response only that one pawn needs does not need the asset. Press + on the component's own Responses instead of creating a Defense Rule Set, using the same Required Defender Tags and Result Tag fields. Responses authored there run ahead of the Defense Set, so the two combine rather than compete.
A Defense component with nothing authored and no Defense Set reports the incoming damage unchanged, so dropping it onto an existing pawn changes nothing until you write the first response.

The responses that ship

Add them to Responses in this order to start from a sane list: most situational at the top, the scaling ones at the bottom.
ResponseAnswers whenShips with
SEC InvulnerableThe pawn holds the tags. No arc, so it answers from every direction, and no cost.Damage fixed at 0
SEC Guard as a parryThe pawn holds the parry window's tag and the blow arrives inside the arc.Set Damage Multiplier to 0 and Cost Per Damage to 0
SEC Guard as a blockThe pawn holds the raised guard's tag and the blow arrives inside the arc.60 degree half arc, multiplier 0.2, cost per damage 1
SEC Scale DamageThe pawn holds its defender tags and the attack carries its attack tags, where an empty list passes. Scales a hit: double against a stance-broken enemy, half against a buffed one, less against armor that resists a kind of damage.Multiplier 1, Continue After Claim on
A parry and a block are the same response with different values, so list the parry above the block and a hit inside the parry window never reaches the block. SEC Scale Damage scales a hit rather than answering it, and reports no result tag unless you give it one, so a blow only it touched reads to the attacker as a clean hit.
SEC Parry, SEC Block, SEC Damage Modifier and SEC Damage Type Resistance show as Deprecated in the response picker. A rule set already holding them keeps answering hits the way it did. Author new responses with SEC Guard and SEC Scale Damage.

Where the tags come from

A response reads the pawn's current state tags and nothing else. Whatever grants a tag decides when the response is live: a reaction on an enemy, an input-driven ability on a player, or a montage window that holds a tag for the frames it covers.
That is the seam between the two halves of a defense. The reaction picks the animation and plays it; the response prices a hit that lands during it. One enemy parry reaction plus one parry SEC Guard covers the whole move, and neither knows about the other beyond the tag they share.

Author a response

What a guard reads

SEC Guard adds two fields of its own.
FieldSets
Arc Half Angle DegreesHalf the width of the arc the blow must arrive inside, in degrees to either side of straight ahead. 60, the starting value, accepts anything up to 60 degrees off the front; 180 accepts all round. A blow carrying no direction counts as frontal, so an attack with none cannot slip past a raised guard.
Damage MultiplierHow much of the hit still lands. 0 stops it completely, which is a parry; 0.2, the starting value, lets a fifth through as chip damage, which is a block; 1 changes nothing.
SEC Scale Damage has a Damage Multiplier too, with no upper limit: 2 doubles the hit, 0.5 halves it. SEC Invulnerable adds nothing; it takes the whole hit.

What every response carries

Every response carries these.
FieldSets
Required Defender TagsTags the pawn must all hold for this to answer, such as those the parry, guard, or dodge ability grants while it runs. Empty answers whatever the pawn is doing.
Blocked Defender TagsTags that stop this answering when the pawn holds any of them, such as a stagger. Empty stops nothing.
Result TagWhat to call this answer, reported to the attacker so its swing and its impact effects can react. Unset reports nothing, which suits armor that only shaves damage.
Required Attack TagsTags the incoming attack must all carry for this to answer, read off the attack's Damage Tags. Empty answers whatever the attack is. A parent tag covers everything beneath it, so SEC.Damage.Elemental answers fire, ice and lightning.
Blocked Attack TagsTags that stop this answering when the attack carries any of them. List SEC.Attack.Unblockable here on a guard and an attack carrying that tag falls through to whatever sits below.
Continue After ClaimKeep running the responses below this one after this one answers, so a resistance can shave what a block let through. Off on SEC Guard and SEC Invulnerable, as a parry wants, and on for SEC Scale Damage.
Cost Vital TagVital this answer charges, such as stamina for a raised guard. Leave it unset and the answer is free, which also means the pawn needs no vitals at all.
Flat CostUnits charged per hit, whatever the blow was worth. Ignored while Cost Vital Tag is unset.
Cost Per DamageExtra units charged per point of incoming damage, measured against the blow before anything reduced it. 1 charges the whole hit to the vital, 0 turns the scaled part off. Ignored while Cost Vital Tag is unset, so the 1 that SEC Guard ships with charges nothing until you point that field at a pool.
Spend Remainder when UnaffordableTake whatever the vital has left when it cannot cover the full charge. The answer is refused either way and the hit falls through to the responses below; this decides only whether the pool empties on the way, raising its depleted tag and firing its depleted event, for a guard meant to break on the blow it could not afford. Off by default.
Vital Damage MultipliersVitals this response treats differently from health. Empty and one Damage Multiplier covers every vital, so a block that halves health halves stance with it. Add a row to let stance or poise through at its own rate.
Working out the answer spends nothing. The component charges what the responses cost afterward, so Preview Incoming Damage can run the same walk on any machine and show a player what a hit would cost before it lands.

Worked examples

Frames where the pawn takes nothing

Give the ability a tag while it runs, put SEC Invulnerable at the top of the list, and point Required Defender Tags at that tag.
Details
SEC Invulnerable
Defender Gates
Required Defender Tags
1 Gameplay Tag
SEC.State.Invulnerable
Blocked Defender Tags
0 Gameplay Tags
Result
Result Tag
SEC.Defense.Block
Defense Rule
Continue After Claim
Attack Gates
Required Attack Tags
0 Gameplay Tags
Blocked Attack Tags
0 Gameplay Tags
Cost
Cost Vital Tag
None
Flat Cost
0
Cost Per Damage
0
Spend Remainder when Unaffordable
Vital Damage
Vital Damage Multipliers
0 Array elements
Takes the hit for nothing while the pawn holds the tag. No arc, so it answers from every direction, and no cost.
Damage is zero from any direction, at no cost. SEC.State.Invulnerable ships as a starting tag for a boss in an immune phase or an actor a script has put out of reach. The blow still lands, still plays its impact effect, and still reports back.
For the invulnerability frames of a dodge, where a sweep should attempt nothing at all, list SEC.State.Intangible in Pass Through Tags on the attacker's melee trace instead. That tag is already in the shipped list, so a montage window holding it across the roll is the whole setup. Reach for SEC Invulnerable when the hit has to resolve, or when damage arrives from something other than a sweep.

A parry, front only

Give the parry ability a tag while its window is open and put a SEC Guard above the block. A Guard starts out as a block, so set Damage Multiplier to 0 for a parry that lets nothing through, Cost Per Damage to 0 so it costs nothing, and Result Tag to SEC.Defense.Parry. Arc Half Angle Degrees at 60 keeps it to the front, 60 degrees to either side.
Details
SEC Guard
Guard
Arc Half Angle Degrees
60
Damage Multiplier
0.00
Defender Gates
Required Defender Tags
1 Gameplay Tag
Player.State.Parrying
Blocked Defender Tags
0 Gameplay Tags
Result
Result Tag
SEC.Defense.Parry
Defense Rule
Continue After Claim
Attack Gates
Required Attack Tags
0 Gameplay Tags
Blocked Attack Tags
0 Gameplay Tags
Cost
Cost Vital Tag
None
Flat Cost
0
Cost Per Damage
0
Spend Remainder when Unaffordable
Vital Damage
Vital Damage Multipliers
0 Array elements
A Guard set up as a parry: nothing lands, nothing is charged, and it answers only while the parry ability holds its tag and the blow arrives inside 60 degrees of straight ahead.
A blow from the front inside the window does nothing. A blow from behind falls through to whatever sits below, so a parry and a block coexist without either of them naming the other.

A block that costs stamina

Give the guard ability a tag it holds while the guard is up, put a second SEC Guard under the parry, and point Cost Vital Tag at the stamina pool. The arc and the multiplier stay at their starting values.
Details
SEC Guard
Guard
Arc Half Angle Degrees
60
Damage Multiplier
0.20
Defender Gates
Required Defender Tags
1 Gameplay Tag
Player.State.Guarding
Blocked Defender Tags
1 Gameplay Tag
Player.State.Staggered
Result
Result Tag
SEC.Defense.Block
Defense Rule
Continue After Claim
Attack Gates
Required Attack Tags
0 Gameplay Tags
Blocked Attack Tags
0 Gameplay Tags
Cost
Cost Vital Tag
SEC.Vital.Stamina
Flat Cost
5
Cost Per Damage
1
Spend Remainder when Unaffordable
Vital Damage
Vital Damage Multipliers
0 Array elements
A Guard set up as a block. Charges 5 stamina plus 1 per point of the incoming blow. A pawn that cannot pay drops through to whatever sits below.
A response's charge is Flat Cost plus Cost Per Damage times the blow before anything reduced it. The values above cost 45 stamina against a 40 damage swing.
Running out is a guard break. Before a costed response answers, the component asks whether the pawn can pay. One that cannot pay steps aside and the next response down takes the hit, so an exhausted pawn eats the blow at whatever the responses under the block make of it. Two responses drawing on one vital are measured against a running total, so a pool that covers one of them does not cover both.
The pool comes from the pawn's Vitals component. A pawn with a costed response and no vitals component answers for free and names itself once in the Output Log.

Armor

Put a SEC Scale Damage at the bottom of the list and name the kind of damage it resists in Required Attack Tags.
Details
SEC Scale Damage
Scale
Damage Multiplier
0.60
Defender Gates
Required Defender Tags
0 Gameplay Tags
Blocked Defender Tags
0 Gameplay Tags
Result
Result Tag
None
Defense Rule
Continue After Claim
Attack Gates
Required Attack Tags
1 Gameplay Tag
SEC.Damage.Physical.Slashing
Blocked Attack Tags
0 Gameplay Tags
Cost
Cost Vital Tag
None
Flat Cost
0
Cost Per Damage
0
Spend Remainder when Unaffordable
Vital Damage
Vital Damage Multipliers
0 Array elements
Shaves 40 percent off slashing damage and carries on down the list, so it trims whatever the guards above it let through.
FieldSets
Required Attack TagsWhich kind of damage this resists, matched against the attack's Damage Tags. A parent tag covers everything beneath it, so SEC.Damage.Physical resists slashing, piercing, and bludgeoning at once. Leave it empty to scale every hit, which is flat armor.
Damage MultiplierHow much of the hit still lands. Starts at 1, which changes nothing.
Result TagLeave it unset for plain armor, which shaves the damage without telling the attacker anything.
This response answers by what the attack is rather than by what the pawn is doing, which is why it ships with Continue After Claim on, and a hit that only armor touched reports no result tag and reads to the attacker as a clean hit. Melee Trace covers the damage tags an attack carries and where it picks them.

Where the responses come from

Most situational firstA hit enters at the top
1
What the pawn is carrying
Weapon Defense Set on each held item, gathered through Get Defense Sets
Runs in the order the items were equipped, and stops the moment an item is put down. A shield in the off hand contributes alongside the sword.
2
Responses on the component
SEC Defense > Responses
The pawn's own answers: its dodge frames, its parry, its stance. Authored on the pawn, so they hold whatever it is holding.
3
The shared set
SEC 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.
FieldSets
Defense SetA shareable list of responses, for armor or a stance several characters use. Runs last, under everything in Responses, so a broad resistance here shaves whatever the answers above it let through. Empty means everything is authored on this pawn.
ResponsesResponses authored on this pawn alone, running after whatever the pawn is carrying brings and before the Defense Set.
Details
SEC Defense
SEC
Defense
Defense Set
DA_Defense_KnightArmour
Responses
3 Array elements
Outcome Effects
0 Array elements
Responses run top down. Whatever the pawn is carrying answers first, then these, then the Defense Set.

Pointing several characters at the same set

Set more than one Defense component's Defense Set to the same asset, DA_Defense_KnightArmour from the walkthrough above or a copy authored for another archetype, to give every pawn carrying it the same answers. Edit the asset once and every pawn pointed at it picks up the change.

A weapon that brings its own

Fill in Weapon Defense Set on a weapon Blueprint built on SECWeaponBase and point it at a rule set holding the parry, the block, or whatever the weapon is worth. Arm the enemy through the equipment component's Starting Loadout or an Equip Actor call, and it answers with those for as long as it holds the item.
A shield in the off hand works the same way. Everything held that carries a set contributes, in the order the pawn equipped them, and all of them answer ahead of the pawn's own responses. EnemyCharacterBase gathers them from its equipment already. See Weapons.

Telling the attacker what happened

Every response that answers adds its Result Tag to the result, and that reaches the attacker in the damage result's Result Tags. Two things read them.
The attacker's melee trace. Skip Record Tags on the attacker's trace component lists the outcomes that leave the target hittable for the rest of the swing. A match means the swing was not spent, so it can connect again on a later frame. No match records the hit, so a parry or a block costs the attacker that swing. Both readings are legitimate; pick per game. See Melee Trace.
Hit effects. An effect on the damage config sits out a hit through Suppress on Result Tags, so a parried blow need not shake the screen or spray blood. Require Any Result Tags does the opposite and gives a parry its own sparks.
Four tags ship: SEC.Defense.Parry, SEC.Defense.Block, SEC.Defense.Dodge, and SEC.Defense.Clash. A tag of your own works the same way, and listing a parent covers everything beneath it.
Outcome on a defense result, and the outcome enum it holds, are deprecated: read Result Tags instead. SEC Parry (Deprecated), SEC Block (Deprecated) and SEC Invulnerable still write an outcome, while SEC Guard, SEC Scale Damage and the two other deprecated responses leave it at Unguarded, so a Blueprint branching on it reads a guarded hit as unguarded.
A parry, block or invulnerable response that answers a hit without a Result Tag leaves the attacker unable to tell what happened, so the swing is spent as if the blow had landed. The Output Log names the response once when that happens.

What the pawn does about it

Outcome Effects on the Defense component, and on a Defense Rule Set, are what the pawn does beyond taking the damage: a spark or a screen shake, a counter window it grants itself, a stagger it sends back to whoever swung. These are the same effects an attack authors on its damage config, so each carries the same outcome gates and picks the sides it lands on.
Gate one on Require Any Result Tags and it answers a single outcome. A parry that opens a counter window is one row:
SettingValue
EffectSEC Apply Gameplay Effect
Require Any Result TagsSEC.Defense.Parry
Gameplay EffectThe effect holding the window open
Affected SidesTarget
They run once the damage is off the pawn's pools, so an effect reading Was Fatal or a drained pool sees what the hit did.
AdvancedWhere the consequences come from
The component gathers the list the way it gathers responses: whatever the pawn is carrying hands its own over, then the component's own list, then the Defense Set. A set that arrives twice, carried and assigned, counts once. Order carries no meaning here, because each consequence that passes its gates runs, while responses stop at the first one that claims the hit.
Run Outcome Effects is the call for a project that works the damage steps by hand instead of calling Resolve Defense and Apply Damage. Call it last, once health has come off.

Debug it

Press Play and swing at the pawn with the tag held, then without it.
SEC.Debug.Melee.DrawTracing 1    // The attacker's sweep, so you can see the blow reach the pawn
Filter the Output Log to LogSECDefense. The defense path names each problem once rather than every frame, and the four it reports cover most of what goes wrong: a response that charges a vital the pawn has no component for, a response that answered without a Result Tag, a pawn with no health pool to take the damage off, and an attack listing the health pool in its Additional Vital Damage.
Preview Incoming Damage on the component reaches the same answer as the real resolve and charges nothing, so a debug widget can print what any hit would cost before it lands.
AdvancedThe pawn is hit and nothing changes
In the order worth checking:
  • Nothing grants the tag. Required Defender Tags names a tag no ability, reaction or montage window ever holds, so the response never gets its turn. This is the common one and it logs nothing.
  • Handle Incoming Damage is not implemented. Without the SEC Damageable interface on the pawn, SEC Deal Damage falls back to Unreal's point damage and the Defense component never runs.
  • The blow came from outside the arc. A Guard measures the direction the hit arrived from against the pawn's real facing. A hit from behind falls through to whatever sits below.
  • The attack carries a tag the response turns away. A tag in Blocked Attack Tags, such as SEC.Attack.Unblockable, lets the blow past, and a Required Attack Tags entry the attack lacks keeps the response silent.
  • The pawn cannot pay. A costed response the pawn cannot afford steps aside on purpose, which is the guard break.
  • A response above it claimed the hit. The first response that answers ends the walk unless it has Continue After Claim ticked.
  • The call ran off the server. Charging a cost and draining health both need the authority.
AdvancedStance, poise and other vital damage
An attack can carry damage to vitals other than health. One Damage Multiplier covers every vital by default, so a block that halves the health damage halves the stance damage with it.
Add a Vital Damage Multipliers row on the response to give one vital its own rate: name the vital's tag and set how much of it still lands. 0 stops that vital, 1 passes it untouched, and above 1 raises it, which is how you author a block that costs extra stance.
The walk reports the health figure and the extra vital damage separately, so a project applying them by hand has each one. See Vitals.
AdvancedScaling a hit by what the pawn is
SEC Scale Damage with Required Defender Tags filled in scales the hit while the pawn holds those tags. It has no arc, and it multiplies the hit by Damage Multiplier: 2 doubles it, 0.5 halves it, 1 changes nothing.
It ships with Continue After Claim on and reports no result tag unless you give it one, so a hit that only this touched reads to the attacker as a clean hit and the swing is spent normally. Gate it on SEC.State.StanceBroken for the window where a guard-broken enemy takes extra, or on a buff tag for a target that takes less.
Its multiplier applies to every vital the hit carries, so pair it with a Vital Damage Multipliers row when one vital should scale at its own rate.
AdvancedBringing responses in from somewhere other than a weapon
Two interfaces cover the rest of the cases, and both are Blueprint-implementable from Class Settings.
InterfaceWhereWhat it answers
SEC Weapon Defense Set ProviderOn the itemGet Weapon Defense Set, for an equippable that is not a weapon Blueprint.
SEC Defense Set ProviderOn the pawn, or on any component of itGet Defense Sets, one entry per thing in force, for a pawn that gathers its own way, or a component that carries the pawn's weapon.
The component stores nothing. It asks the pawn and its components each time it works a hit out, so a set stops answering the moment the pawn stops carrying what brought it. Returning an empty list leaves the pawn on its own responses.
For a list built some other way again, override Get Effective Responses on the component and return the responses in the order you want them run.
AdvancedWriting a response of your own
Subclass SEC Defense Response in Blueprint and implement two events. Your response gets the same Required Defender Tags, Blocked Defender Tags, attack tags, cost and Result Tag fields as the ones that ship, and the component checks the tags and reports the Result Tag for it.
EventDo
Should ApplyJudge whether this response handles the hit and change nothing. The context carries the defender, the pawn's state tags, the hit, and the blow before anything reduced it.
ApplyChange what the hit is worth: scale or zero Final Damage.
Should Apply runs only after the tag checks passed, and Apply only after Should Apply agreed and the component found the cost affordable, so a response has no reason to re-check its own gates.
A parry that scales with a stat, a block that only answers heavy attacks, a resistance keyed to a boss phase: each is one Should Apply branch.
A response subclassed straight from SEC Defense Rule gets no defender tags or Result Tag from the component, so it checks its own tags in Should Apply and adds its own result tag in Apply. Get Display Name on SEC Defense Rule is deprecated and nothing in the plugin calls it; the editor names a response by its class's display name. An override keeps working.
AdvancedCosts against a project's own resources
Can Afford Response Cost and Pay Response Cost on the component are the seam. The defaults read and drain the pawn's Vitals component; override both together for a project running its own pools.
The component asks Can Afford Response Cost while it works a hit out, so that override must change nothing: a response the pawn cannot pay for steps aside rather than answering. Pay Response Cost runs afterward, on the authority, and reports how much came off. A response with Spend Remainder when Unaffordable ticked also asks Get Payable Response Cost how much the pool can still give, so override that one too.
A pawn that keeps its states somewhere other than an ability system overrides Get State Tags in the same way, and every tag gate reads from what it returns.
AlternativeA pawn wired through Event Any Damage
Call Resolve Defense and Apply Damage (Any Damage Event) instead. It takes the loose numbers Unreal's damage event hands over and works the blow's direction out from where the attacker is standing, so a directional response still has a bearing to measure against.
It takes the surviving damage off the health pool too, so nothing after it should subtract health again. Prefer the version in the quick start wherever a damage info exists, since that one carries the exact hit and the attack's own tags.
AlternativeRunning your own health pool
Call Resolve Incoming Damage on the component instead of the one-node version. It runs the responses and charges what they cost, then hands back the result without draining health or the extra vitals. Subtract its Damage Applied from your own health variable and return the result unchanged, so the attacker still gets the tags.
To drive each step yourself, Evaluate Defense, Apply Defense Result and Fill Damage Result are the same act split three ways: work out the answer, charge the costs on the server, then stamp the decision into the damage report.
MultiplayerMultiplayer
Charging a cost and draining health both need the authority, so run Resolve Defense and Apply Damage on the server. A call anywhere else charges nothing and drains nothing, and the result it hands back is advisory.
Preview Incoming Damage reaches the same answer on any machine, so a guard meter or a damage-preview widget on the owning client can call it freely.
Vitals replicate on their own, so the client sees the stamina a block spent without any extra wiring. See Vitals.

PageWhy
TelegraphsHow an enemy learns a blow is coming in time to raise the guard these responses price.
Reaction SystemThe other half of a defense: the reaction plays the parry, the response decides what it was worth.
Melee TraceWhere the hit comes from, Skip Record Tags, Pass Through Tags, and the damage tags an attack carries.
VitalsThe pools a costed response charges, and the health a resolved hit comes off.
WeaponsWeapon Defense Set, and arming an enemy so it arrives.
Animation IntegrationMontage windows that hold a state tag for exactly the frames a response should answer on.