Weapons

Documentation Unreal Engine AI Weapons Combat

Arm an enemy: build a weapon Blueprint, drop it in the starting loadout, and the enemy spawns holding it and fighting from its moveset.


An enemy that spawns with its weapon in hand, sweeping from the blade, fighting from the moveset the weapon brings. Give the same skeleton a bow instead and it fights like an archer.

Set it up

60 seconds
  1. 1

    Make the weapon Blueprint

    Right-click in the Content Browser, Blueprint Class, All Classes, and pick SEC Weapon Base. Name it BP_Sword.
    Add a Static Mesh component for the blade and drag it onto DefaultSceneRoot so the mesh is the root. The weapon attaches by its root, so a mesh whose pivot sits where the hand grips it needs no offset.
  2. 2

    Set the hand it sits in and the moveset it brings

    Open Class Defaults. Attach Socket is the socket on the enemy's mesh the weapon hangs from, hand_r out of the box. Weapon Action Set is the moveset the enemy fights from while holding it.
    BP_Sword
    Weapon
    Attach Socket 
    Weapon Action Set
    None
    Attach Socket has to exist on the enemy's skeletal mesh. Leave the set empty to keep the enemy's own moveset.
  3. 3

    Tell it where it cuts

    Add sockets to the weapon mesh at the hilt and the tip, then add one entry to Trace Sockets spanning them.
    BP_Sword
    Trace Sockets
    IDNone
    ShapeSphere
    Socket Or Bone NameTraceStart
    End Socket Or Bone NameTraceEnd
    Equipping the weapon registers these on the wielder. Releasing it takes them away again.
  4. 4

    Put it in the enemy's loadout

    Open the enemy Blueprint, select its SEC Equipment Component, and add one entry to Starting Loadout naming the weapon class.
    BP_Enemy
    Starting Loadout
    Equippable ClassNone
    Use As Weapon
    One entry per thing the enemy carries. Use As Weapon marks the one it fights with, and Socket Override left empty uses the socket the weapon names itself.
  5. 5

    Play, and watch it swing

    Press Play. The weapon arrives in the enemy's hand, its trace sockets register, and its sets reach the enemy. Run SEC.Debug.Melee.DrawTracing 1 in the console to see the blade sweep.
Use As Weapon on the loadout entry decides whether any of the weapon reaches the enemy. With it off the weapon still spawns, attaches, and looks correct in the hand, while its moveset, its reactions and its animation layer go nowhere. One entry can be the weapon; mark two and the later one takes the slot, releasing the earlier one through Swap Disposal, which destroys it by default.
For the swings to deal damage, the attack montage also needs a trace window. See Melee Trace.

What the weapon gives its wielder

Details
Weapon Defaults
SEC|Weapon
Attach Socket
hand_r
Attach Offset
Identity
Weapon Action Set
DA_ActionSet_Sword
Weapon Reaction Set
None
Weapon Defense Set
DA_SwordGuard
SEC|Animation
Anim Layer To Use
ABP_Sword
SEC|Trace
Trace Sockets
1 Array element
Class Defaults on the weapon Blueprint. Leave a set empty to keep the enemy's own.
FieldDoes
Attach SocketThe socket on the enemy's mesh the weapon hangs from, hand_r by default. A socket that does not exist attaches the weapon at the mesh root and says so in the log.
Attach OffsetNudges the weapon from that socket. Leave it at identity when the mesh is authored with its pivot at the grip.
Weapon Action SetThe moveset the enemy fights from while holding this.
Weapon Reaction SetThe reactions it can answer with, for a parry that exists because it is carrying something to parry with.
Weapon Defense SetHow the wielder answers an incoming hit while holding this: the parry, the block, the resistance the weapon brings.
Anim Layer To UseAn animation layer linked onto the wielder, for locomotion and idles that belong to the weapon rather than the character. Only the equipped weapon's layer links, so an off-hand item does not replace it.
Weapon Action Set and Weapon Reaction Set replace what the AI Config gives. While the enemy holds the weapon its sets win; put the weapon down and the AI Config answers again. A runtime override set from Blueprint still outranks both. Leave either empty and the enemy keeps its own.
Weapon Defense Set adds instead of replacing, since a weapon's parry and a pawn's own armour are both in force at once. Everything held answers, so a shield in the off hand guards alongside the sword, and what the weapons bring runs ahead of the pawn's own responses. A pawn with no defenses of its own gains these by picking the weapon up. The plugin's enemy character gathers the sets off what it holds; a pawn built from scratch does that gathering itself through Get Defense Sets. See Defense System.

Where its swings sweep from

Trace Sockets is where the weapon's swings sweep from. Add sockets on the weapon mesh first (blade_start, blade_end), then one array entry per contact point.
Details
Trace Socket
Trace
ID
Blade
Source Component Tag
None
Shape
Capsule Two Point
Socket Or Bone Name
blade_start
End Socket Or Bone Name
blade_end
Radius
15
Override Trace Filter
One entry in the weapon's Trace Sockets array. Equipping registers it on the wielder.
A socket that names no source of its own sweeps from the weapon's mesh, which is its skeletal mesh when it has one and its static mesh otherwise. Equipping registers these onto the wielder's SEC Melee Trace Component, so a wielder without one registers nothing and the blade sweeps nothing. Per-attack damage comes from the montage notify or the trace component default rather than from the weapon; Melee Trace covers the sweep shapes, the damage config and the montage window.

Arming the enemy

The plugin's enemy character already carries an SEC Equipment Component and an SEC Melee Trace Component. A pawn built from scratch needs both: the equipment component to hold the weapon, the trace component for the weapon's trace sockets to register on.
Details
SEC Equipment Component
SEC|Loadout
Starting Loadout
1 Array element
Equip Starting Loadout On Begin Play
Attach Mesh Component Tag
None
SEC|Equipment
Swap Disposal
Destroy
Teardown Disposal
Destroy
Spawns and holds the pawn's equipment. Enemy Character Base carries one already.
Each Starting Loadout entry is one thing the enemy carries.
Details
Equip Loadout Entry
Loadout
Equippable Class
BP_Sword
Socket Override
None
Use Transform Override
Use As Weapon
One entry spawns one actor and equips it. Turn Use As Weapon off for an off-hand item.
Equippable Class is the weapon Blueprint. Socket Override left empty uses the socket the weapon names itself. Tick Use Transform Override to offset this entry from its socket instead of using the offset authored on the weapon, which an off-hand item usually needs. Use As Weapon marks the one the enemy fights with, so a shield or a torch goes in with it turned off.
Attach Mesh Component Tag picks which of the pawn's meshes equipment hangs off, by component tag. Empty uses the pawn's own skeletal mesh. Untick Equip Starting Loadout On Begin Play to hold the list as data and arm the enemy later with Equip Starting Loadout.
While a weapon is equipped the enemy holds SEC.Weapon.Equipped. Put that in an action's Requires Tags so an unarmed enemy cannot swing a sword it is not holding.
Equipping runs on the server. The weapon actor replicates, and so does which held actor is the weapon, so a client sees the right thing in the right hand and relinks the animation layer itself.

Swapping and dropping

Spawn And Equip puts a new weapon in the hand, Equip Actor equips one that already exists, and Unequip Actor takes one out. Set Equipped Weapon chooses which of the things already held the enemy fights with, and clearing it hands both sets back to the AI Config.
Two fields decide what becomes of a weapon the pawn is done with.
ChoiceWhat happens to it
DestroyRemoved from the level. The default for both fields.
Leave In WorldDetached and left standing where it was, no physics.
DropLeft in the level and asked to drop itself. The weapon's own On Unequipped event receives Should Drop, and turning on physics and setting a lifespan there is a couple of nodes.
Swap Disposal covers the outgoing weapon when a new one replaces it. Teardown Disposal covers what the component spawned when the pawn is destroyed, which is what a game wants when a corpse despawns and its sword stays lying there. A weapon handed in through Equip Actor belongs to whoever made it, so it is released rather than destroyed.
Death releases the enemy's equipment through the SEC Combat Controller Component on the AI controller. Drop Weapon On Death on that component is on by default and releases with Drop; turn it off and death releases with Leave In World instead. Reviving does not re-arm the enemy, so call Equip Starting Loadout on the way back.
On Equipped Weapon Changed fires on the server and on every client when the weapon changes, for a marker on the HUD or an ability that reads a socket. On Equipped and On Unequipped on the equipment component fire on the server for anything held, each handing over the actor it concerns.

Debug it

SEC.Debug.Melee.DrawTracing 1    // Draw the sweeps the weapon's sockets make
Equipping reports its own problems into the Output Log under LogSECEquipment and LogSECEquip. Filter on those two and the log names the entry with no class, the pawn with no mesh to attach to, the socket that does not exist on the wielder's mesh, and the weapon carrying trace sockets that found no melee trace component to register on.
AdvancedIt equips, but the enemy fights the same
  • Use As Weapon is off on the entry. The weapon attaches and contributes nothing.
  • Weapon Action Set is empty, so resolution falls through to the AI Config, which is the point of leaving it empty.
  • A runtime override is set on the pawn's action set component. It outranks the weapon until it is cleared.
  • The weapon answers nothing for this role. A weapon overriding the per-role event and returning none for the enemy's current combat role leaves that role on its AI Config set.
  • A later entry took the weapon slot. A second entry marked Use As Weapon replaces the first and releases it through Swap Disposal, which destroys it by default, so the enemy fights from the last one in the list.
AdvancedIt swings, but the blade sweeps nothing
  • The wielder has no SEC Melee Trace component. The weapon carries its sockets and finds nothing to register them on, and says so in the log.
  • The weapon has no mesh. A socket that names neither a source component nor a Source Component Tag is pointed at the weapon's own mesh, so a weapon with none registers nothing.
  • The socket names do not match the mesh. Socket Or Bone Name and End Socket Or Bone Name have to exist on the weapon mesh.
  • The montage window names a different ID. Socket IDs on the trace window has to match a socket ID exactly. Leave it empty to sweep everything registered.
  • The machine does not detect hits. The trace component turns registration away wherever sweeps do not run, so a client registers nothing and needs nothing.
AdvancedA different set per combat role
Weapon Action Set and Weapon Reaction Set answer the same set for every combat role. To vary them, override Get Weapon Action Set For Role or Get Weapon Reaction Set For Role on the weapon and branch on the incoming role tag. Return nothing for a role to leave that role on its AI Config set.
The equipment component asks again whenever the pawn's combat role changes, so a per-role answer stays current. Refresh Weapon Sets For Role does the same ask by hand, which a pawn driving its own equipment can call with an empty role to get the weapon's default answer.
Weapon Defense Set has no per-role form. Get Weapon Defense Set answers the same for every role, and what it returns composes with the pawn's own instead of replacing it.
AlternativeA weapon that is not a SEC Weapon Base
A weapon can be a plain Actor. Each interface it adds in Class Settings earns it one more thing, and adding none still gets it attached and released with the rest of the pawn's equipment.
InterfaceWhat the weapon gains
noneAttaches at the socket the entry names, and is released on death and on teardown.
SEC Equippable InterfaceIts own socket, offset, mesh, trace sockets and animation layer, and control of how it attaches.
SEC Weapon Action Set ProviderGives the enemy its moveset while equipped.
SEC Weapon Reaction Set ProviderGives the enemy its reactions while equipped.
SEC Weapon Defense Set ProviderGives the enemy its parry, block or resistance while equipped, on top of the pawn's own.
An actor implementing SEC Equippable Interface attaches itself, so call Apply Standard Equip from its On Equipped event for the ordinary behavior. A weapon that places its own pieces, a bow with a quiver for instance, skips that node and does the attaching itself.
Trace sockets register through that interface, so an actor that implements none of it contributes no sweeps.
The actor needs a root component. Attaching moves an actor's root, so one without a root is refused and logs why.
Tick Replicates in its Class Defaults as well. SEC Weapon Base sets that itself, and a plain Actor that leaves it off never reaches a client's hand.
AlternativeEquipping without the component
Nothing requires the equipment component. The nodes under SEC | Equip in the Blueprint palette carry the same act, so a pawn can drive its own equipping instead.
Equip Actor To Wielder asks the weapon to equip itself, and Set Equipped Weapon on the equipment component points combat resolution at it. A pawn with no equipment component pushes the sets itself through Set Provided Action Set and Set Provided Reaction Set on its action and reaction set components, which sit above the AI Config and below a runtime override. Those slots read no weapon, so anything can drive them.
Apply SEC.Weapon.Equipped yourself on this path, since the component is what adds and removes it.
Call the nodes once per item, so a sword in one hand and a shield in the other are two calls. Branch on Has Authority first, since the nodes do what they are told wherever they run.
Apply Standard Equip is the ordinary act on its own: take ownership, make the weapon visible, attach it at the socket, and register the trace sockets it carries. It reports which sockets took, and Apply Standard Unequip needs that list back to remove exactly those.

PageWhy
Melee TraceThe component the weapon's sockets register on, the montage window that opens them, and the damage config.
Action SystemThe moveset Weapon Action Set replaces, and how resolution ranks the weapon against the AI Config.
Reaction SystemWhat Weapon Reaction Set gives the enemy to answer an incoming blow with.
Defense SystemWeapon Defense Set, and how a held item's guard composes with the pawn's own.
Combat RolesThe role tag a per-role weapon set branches on.