Weapons

Documentation Unreal Engine AI Weapons Combat

Give an enemy a weapon from a loadout, with its own moveset, reactions, defenses and trace sockets.


Fill in a loadout entry and the enemy spawns holding its weapon, sockets registered, animation layer linked, and the weapon's own moveset, reactions and defenses in force.

When to Use This

  • Arming an enemy with a sword, a staff, a bow.
  • A weapon that brings its own moveset, so a skeleton with a bow fights differently from the same skeleton with a club.
  • A shield or a torch carried alongside the weapon.
  • Swapping a weapon mid-fight, or leaving it on the ground when the enemy dies.
An unarmed enemy needs none of this. Trace sockets registered straight onto the pawn cover fists and claws; see Melee Trace.

The weapon Blueprint

Create a Blueprint from ASECWeaponBase and add your weapon mesh.
Details
Weapon Defaults (ASECWeaponBase)
SEC|Weapon
Attach Socket
hand_r
Attach Offset
Identity
Weapon Action Set
DA_GreatswordActions
Weapon Reaction Set
None
Weapon Defense Set
DA_GreatswordGuard
SEC|Animation
Anim Layer To Use
ABP_Greatsword
SEC|Trace
Trace Sockets
1 Array element
Class Defaults on the weapon Blueprint. Leave a set empty to keep the enemy's own.
Attach Socket is the socket on the wielder's mesh the weapon hangs from. Attach Offset nudges it from there, and it stays at identity when the mesh is authored with its pivot where the hand grips it.
Weapon Action Set and Weapon Reaction Set are what the weapon gives its wielder. Fill in the action set and the enemy fights from that moveset while holding this weapon. Fill in the reaction set for a defence the weapon makes possible, a parry the enemy can only perform while carrying something to parry with. Leave either empty and the enemy keeps what its AI Config gives it.
Weapon Defense Set is how the wielder answers an incoming hit while holding this: the parry, the block or the resistance the weapon itself brings. The two sets above resolve to one winner; this one adds to what the pawn already answers with, since a weapon's parry and the pawn's own armour are both in force at once. A pawn with no defenses of its own gains these by picking the weapon up and loses them by putting it down. Everything held answers, so a shield in the off hand guards alongside the sword. Leave it empty for a weapon that changes nothing about being hit. See Defense System for what a response can do and the order they run in.
Anim Layer To Use links an animation layer onto the wielder while the weapon is equipped, for locomotion and idles that belong to the weapon rather than the character.

Trace sockets

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 hit zone:
Details
Trace Socket (FSECTraceSocket)
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.
Equipping the weapon points each socket at the weapon mesh and registers it on the wielder's trace component. Releasing the weapon takes those sockets away again, so a dropped weapon stops sweeping.
Per-attack damage comes from the montage notify or the trace component default, not from the weapon. Melee Trace covers the sweep, the damage config and the montage window.

Arming the enemy

AEnemyCharacterBase already carries a SEC Equipment Component. Add one yourself for a pawn built from scratch.
Details
SEC Equipment Component (USECEquipmentComponent)
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. AEnemyCharacterBase carries one already.
Add one entry to Starting Loadout per thing the enemy carries:
Details
Equip Loadout Entry (FSECEquipLoadoutEntry)
Loadout
Equippable Class
BP_EnemyGreatsword
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. Leave Socket Override empty to use the socket the weapon names itself. Use As Weapon marks which entry the enemy fights with, so a shield or a torch goes in with it turned off.
That is the setup. The weapon arrives in the enemy's hand on spawn, its trace sockets register, its animation layer links, and its sets reach the enemy.
An enemy has to be holding the weapon before any trace runs. A montage that opens a trace window on an enemy with an empty loadout sweeps nothing.

Swapping and dropping

Spawn And Equip puts a new weapon in the hand and Unequip Actor takes one out. Swap Disposal decides what happens to the weapon being replaced, Teardown Disposal what happens to the pawn's own weapons when the pawn is destroyed. Both default to removing the weapon from the level.
To leave a weapon on the floor, set the disposal to Drop and turn on physics from the weapon's On Unequipped event, which receives Should Drop with a suggested impulse and lifetime.
Death releases the enemy's equipment through the combat controller. bDropWeaponOnDeath decides whether it asks the weapon to drop itself. Reviving does not re-arm the enemy; call Equip Starting Loadout for that.

Beyond the weapon base

AdvancedAnswering with a 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.
Weapon Defense Set has no per-role form. Get Weapon Defense Set answers the same for every role, and the responses compose with the pawn's own instead of replacing them.
AdvancedA 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 EquippableIts 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 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.
The actor needs a root component. Attaching moves an actor's root, so one without a root is refused and logs why.
AdvancedEquipping without the component
Nothing requires the component. SEC Equip Statics carries the same act as Blueprint nodes, so a pawn can drive its own equipping instead.
Equip Actor To Wielder asks the equippable 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.
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.
C++Where the weapon's sets land
The equipment component reads the weapon and pushes the result into the pawn:
Pawn->ActionSetComponent->SetProvidedActionSet(WeaponActionSet);
Pawn->ReactionSetComponent->SetProvidedReactionSet(WeaponReactionSet);
Those slots sit above the AI Config and below the runtime override. Pushing null hands resolution back to the AI Config, which is what an unarmed pawn resolves to. Neither set component reads a weapon, so anything can drive the slots.
The defense set travels the other way: nothing pushes it. As a hit is worked out, the Defense component asks the pawn for its defense sets through ISECDefenseSetProvider::GetDefenseSets, and AEnemyCharacterBase answers with the set from every held actor implementing ISECWeaponDefenseSetProvider, in equip order. Those responses run ahead of the pawn's own.
USECEquipmentComponent::GetEquippedWeapon answers which held actor is the weapon, and SetEquippedWeapon chooses among what the component already holds.

Integration

SystemLink
Melee TraceThe sweep, the damage config, and the montage window that opens a trace.
Action SystemWeapon Action Set lands at priority 2 in action set resolution.
Reaction SystemWeapon Reaction Set lands at priority 2 in reaction set resolution.
Animation IntegrationThe weapon's animation layer, and the montage windows its attacks open.
MultiplayerEquipping runs on the server; the weapon actor and the reference replicate from there.