Enemy Weapons

Documentation Unreal Engine Combat Framework AI Weapons Items

Arm an enemy with the same items the player draws: list them in its Loadout, give its AI moves for each item and role, let it start on a random weapon, fight on with its fists once disarmed, and drop what it holds when it dies.


An enemy holds the same items the player draws. A sword in an enemy's hand is the sword a player picks up: it sweeps the same blade, lends the same block and parry, and drops where the enemy falls.

Set it up

3 minutes
  1. 1

    Pick the item

    Use one of the demo's items, Item_UCF_Sword in Demo/Weapons/Sword or Item_UCF_TwoHandedBaton in Demo/Weapons/TwoHanded, or make one of your own the way a player's item is made: an Item Definition with an Equippable fragment carrying its Trace Sockets, a Visuals fragment carrying its Mesh, and a World Item fragment so it drops when the enemy dies. Items covers each fragment.
  2. 2

    List it in the enemy's Loadout

    Open an enemy Blueprint built on UCF Enemy Character Base, select its Loadout component, and add the item to Starting Items.
    BP_MyEnemy
    ▾Loadout > Starting Items
    Index [ 0 ]
    None▾
    Drawn in order as the enemy begins play, the way the player's character draws.
  3. 3

    Give its AI moves for the item

    Press + on Item Sets and fill the row in. Leave Combat Role empty and the row serves every role.
    BP_MyEnemy
    ▾Loadout > Item Sets > Index [ 0 ]
    Item
    None▾
    Action Set
    None▾
    Reaction Set
    None▾
    While the enemy holds the sword, its AI picks from these sets in place of its AI Config's.
  4. 4

    Play, and watch it swing

    Press Play. The sword hangs in the enemy's right hand. Run UCF.Debug.Melee.DrawTracing 1 to see the blade sweep during each strike, and UCF.Debug.EnemyActions 1 to see the actions of the set its row names. Kill the enemy and the sword drops to the ground, where the player can pick it up.
The item only says where a swing sweeps from. Each attack montage still needs a UCF Melee Trace Window over its strike frames, naming the item's socket IDs or none to sweep them all. See Melee Trace and Damage.

What an enemy holds

UCF Enemy Character Base carries a UCF Equipment Manager, the component that draws the player's items, and a UCF Enemy Loadout, named Loadout, which says what the enemy starts holding and what each item gives its AI. The enemy holds an item the way the player's character does:
The item'sOn the enemy
Place in the handThe Equipment Manager's Body Places say where each place sits on the body: the main hand at hand_r and the off hand at hand_l to start with. Two one-handed swords take both hands, and an item needing a place another holds puts that one away.
Trace SocketsRegister on the enemy's UCF Melee Trace while the item is in hand, and come off when it leaves.
Guard fragmentLends its block and parry rules to the enemy's Defense component while the item is in hand. See Defense.
Anim Layer ClassLinks onto the enemy's mesh through its UCF Anim Manager, as it does on the player's character.
Action GraphHands the enemy the item's moves, for an enemy that plays combos from it. See Action Graphs in Action Sets.
The Equipment Manager's Default Item is what the enemy holds while it holds nothing else, such as its fists. The demo's enemies name Item_UCF_Unarmed, whose trace sockets sit on the mannequin's hands. Clear it on a character of your own whose skeleton has no such bones.
While an item other than the Default Item drives combat, the enemy carries UCF.Weapon.Equipped. Put that tag in an action's Requires Tags so an enemy with empty hands cannot swing a sword it is not holding.

Moves for each item and role

An enemy's AI picks from an Action Set and answers with a Reaction Set. Item Sets on the Loadout swaps both for the item the enemy holds.
Item Sets fieldWhat it is
ItemThe item this row is for, read against the item driving combat: the weapon in hand, or the Default Item while the enemy holds nothing else.
Combat RoleThe role this row is for, such as UCF.Role.Supporter. Empty serves every role, and a row naming the role the AI plays now wins over it, whatever their order.
Action SetThe actions the AI picks from while the row applies. None leaves the AI on its AI Config's actions for the role.
Reaction SetThe reactions the AI answers with while the row applies, such as a parry with a sword or a dodge with bare hands. None leaves the AI on its AI Config's reactions for the role.
The row for the item in hand and the role the AI plays replaces the AI Config's sets for that role, and the Loadout picks again whenever the item or the role changes. With no row for the item, the AI fights with its AI Config's sets.
BP_UCF_EnemyCharacter, the parent of every demo enemy, carries these rows:
ItemCombat RoleAction SetReaction Set
Item_UCF_TwoHandedBatonAnyNone, so the AI Config's sets for the roleReactionSet_UCF_TwoHanded
Item_UCF_SwordUCF.Role.AttackerActionSet_UCF_Sword_AttackerReactionSet_UCF_Sword
Item_UCF_SwordUCF.Role.SupporterActionSet_UCF_Sword_SupporterReactionSet_UCF_Sword
Item_UCF_SwordAnyNoneReactionSet_UCF_Sword
Item_UCF_UnarmedUCF.Role.AttackerActionSet_UCF_Unarmed_AttackerReactionSet_UCF_Unarmed
Item_UCF_UnarmedUCF.Role.SupporterActionSet_UCF_Unarmed_SupporterReactionSet_UCF_Unarmed
Item_UCF_UnarmedAnyNoneReactionSet_UCF_Unarmed
The sword and fist sets sit in Demo/AI/ActionSets, the reaction sets beside each item. The combo enemy, BP_UCF_ComboEnemy, names its own combo sets in the sword's and the fists' Attacker rows, and the supporter sets above in their Supporter rows, so an enemy waiting its turn lunges, slashes or jabs now and then instead of playing its strings. The Freeflow crowd, BP_UCF_EnemyCharacter_Unarmed, names ActionSet_UCF_Freeflow_Attacker and ActionSet_UCF_Freeflow_Supporter in its fists' rows: copies of the unarmed sets at half their play rates, so each punch's warning comes early enough to answer.
ReactionSet_UCF_Sword parries a telegraphed swing of the player's on AM_UCF_Sword_EnemyParry, the player's sword parry with its Parrying window held open from 0.025 to 0.53 seconds, so a parry the enemy raises as the swing is announced is still open when the blow lands. ReactionSet_UCF_DualSwordBoss parries on the same montage.
Item Sets left empty writes nothing, so the AI Config's sets apply and other code can set the AI's sets through Set Provided Action Set and Set Provided Reaction Set. Once the list holds a row, the Loadout owns those two slots and replaces whatever other code put there.

A random weapon each spawn

Random Starting Items lists ways the enemy can start. One entry is picked at random each time the enemy begins play and drawn in place of Starting Items, so an enemy spawned again, at an arena's reset for one, can hold something else.
Random Starting Items fieldWhat it is
ItemsThe items drawn when this entry is picked, in order, as Starting Items are drawn. Empty starts the enemy on its Default Item, its fists.
WeightHow often this entry is picked against the others. 0 never picks it.
BP_UCF_ComboEnemy_RandomWeapon, the Over Shoulder arena's enemy, lists three entries of weight 1: the baton, the sword, and an empty one for its fists. Leave the list empty and the enemy draws Starting Items.
MultiplayerWhere the pick is made
The pick runs on the server as the enemy begins play, and the drawn items reach every machine through the Equipment Manager. An enemy whose AI Config ticks Deterministic picks from its own seeded stream, so the same seed hands the same enemy the same weapon. See Determinism.

A disarmed enemy fights on

An enemy that loses its weapon, to the player's execution for one, falls back on its Default Item and fights on with its fists. An Item Sets row for the Default Item gives it moves for bare hands; without one it fights with its AI Config's sets.

What it drops when it dies

With Drop Weapon on Death ticked on the UCF Combat Controller of the enemy's AI controller, which it is by default, each item the enemy holds but its Default Item drops as an item a player can pick up. An item with no World Item fragment is put away instead, so nothing is left lying. Untick it and the items stay in the enemy's hands.
On Item Dropped on the Loadout names each dropped item on the server. Bind it to clean the items up later, and check Is Valid first, since a player may have picked one up. BP_UCF_Arena, the demo's arena actor, listens to it on each of its enemies, and when a style plate resets the arena it destroys the items its enemies dropped that still lie there, then puts each enemy back fresh. The player picks a dropped item up like any other: see Pickups, Drops and Holders.

An enemy that picks items up

Add a UCF Inventory component to the enemy Blueprint. The enemy then starts holding what the inventory starts with, drawn through the Equipment Manager's Equip Item If Free, and leaves the Loadout's own Starting Items and Random Starting Items undrawn, with a warning while they are filled.
To have the enemy take an item, call Try Pick Up on the world item from the server, naming the enemy as the picker: the item goes into its inventory. Then call Equip Item If Free on its Equipment Manager to put it in hand. At death it drops what it holds as any enemy does. The demo's enemies carry no inventory.

Posture: what a parry does to an enemy

A parry the player lands sends the attacker UCF.Event.ParryRecoil, and the enemy answers through an ability in its Starting Abilities.
  • An ordinary enemy recoils. The demo's enemies carry GA_UCF_ParryRecoil, which plays the recoil and stops the swing, so a perfect block staggers every ordinary enemy.
  • A boss takes posture instead. The demo's boss parent, BP_UCF_BossCharacter, carries GA_UCF_BossPosture in place of the recoil: a clean parry takes Drain Per Parry off the boss's own UCF.Vital.Stance row, and when the row runs out it sends UCF.Event.GuardBreak, which starts the ordinary stun, GA_UCF_Stun, a window to strike.
The dual-sword boss carries 150 Stance and loses 30 a parry, so the fifth clean parry of one exchange breaks it. Its Stance refills 15 a second, starting only 2.5 seconds after its last drain, so the parries of one exchange add up. Tune the break with Drain Per Parry against the row's maximum. See Defense and Vitals.

In the demo

LVL_UCF_Demo puts a crowd or a boss in each arena, every one of them on the enemy AI and built on BP_UCF_EnemyCharacter.
ArenaEnemiesWhat they hold
FreeflowEight BP_UCF_EnemyCharacter_UnarmedTheir fists, punching at half speed from the Freeflow sets. The crowd takes turns through its combat roles and attack tokens, so only a few swing at once.
Over ShoulderSix BP_UCF_ComboEnemy_RandomWeaponThe baton, the sword or their fists, picked each time they spawn, playing combos from that item's action graph, one enemy at a time.
SoulslikeThe dual-sword boss, BP_UCF_DualSwordBossTwo of the player's swords, through its Loadout.
The dual-sword boss is the boss parent holding two Item_UCF_Sword, one in each hand. Its Action Sets play strings from the sword's action graph, with hyper armor on its heavy strings; below half health it rages and swaps in a faster second phase. Its Reaction Set parries a telegraphed swing on AM_UCF_Sword_EnemyParry, counters once a parry lands, raises the sword's guard for 1.5 to 3 seconds once two blows land within 5 seconds, and dodges back once a run of hits wears its poise down. Its posture breaks under parries, and at 150 health its finisher stun opens it to the player's sword execution, which knocks one sword away; the other drops at its death. Getting Started lists its parts.
The boss parent stands at the arena boss size, 1.2 times the mannequin's width and 1.15 times its height. The dual-sword boss stands at 1.1, so the sword moves it plays and the sword execution fit its body. An arena's reset puts each enemy back at the size it was placed at.
Build on copies of the demo assets. A plugin update replaces the plugin's content and drops any edit made in place: duplicate an enemy or an item into your own content, change the copy, and point your level at it.

Debug it

RunShows
UCF.Debug.Melee.DrawTracing 1Every sweep the held item's sockets make.
UCF.Debug.EnemyActions 1The enemy's actions above its head, from the set its Item Sets row names.
Log LogUCFDamage VerboseEach trace socket as the item registers it, and each hit its swings find.
The Loadout warns under LogUCFBridge: an enemy with no Equipment Manager, an enemy possessed by a controller with no Combat Controller, which then neither follows its role nor drops its items, and Starting Items filled beside an inventory.
SymptomCause
The enemy holds nothingStarting Items is empty and the Equipment Manager has no Default Item, or the enemy is built on Enemy Character Base without the pieces below.
It holds the item and fights as beforeNo Item Sets row names the item, or the row names a role the AI is not playing.
The swings missThe montage's trace window names socket IDs the item does not register.
Nothing drops at deathDrop Weapon on Death is off, or the item has no World Item fragment.
AdvancedKnown limits
  • Two of one item swing with one. An item held outside the first place its Hold Places lists registers its sockets with the place appended (Blade_Off for a sword in the off hand), and the sword's trace windows name Blade. The dual-sword boss hits with its main-hand blade only.
  • An enemy stops short at its approach's distance, the Default Stop Distance on its UCF Approach or a window's own, not at the item's Attack Stop Distance. The demo's enemy parent stops 50 cm short.
AdvancedAn enemy on Enemy Character Base
An enemy built on Enemy Character Base rather than UCF Enemy Character Base holds nothing until it carries what UCF Enemy Character Base adds. Reparenting it onto UCF Enemy Character Base gives all of it at once. Otherwise:
  1. Add a UCF Enemy Loadout, a UCF Equipment Manager and a UCF Anim Manager.
  2. Tag its Mesh component UCF.Montage and UCF.Attachment.Body in Component Tags, so montages play on it and items hang on it.
  3. Call Notify Ability System Ready from its Begin Play, so the item's draw plays its reach and its trace's hits are confirmed.
  4. Tick Use Acceleration For Paths on its Character Movement, under Nav Movement, or it slides along its path in its idle pose.
  5. For flinches and a death fall, add a UCF Physical Reaction and a UCF Anim Effects component and put the reaction abilities, GA_UCF_HitReact, GA_UCF_Stun and GA_UCF_ParryRecoil, in its Starting Abilities.
  6. While it holds UCF.State.ActionsBlocked or UCF.State.PairedAction, put UCF.Action.BlockActions and UCF.Reaction.BlockReactions on it, so a stun or an execution plays out. UCF Enemy Character Base does this itself.
Its melee trace has Team Filter on No Filter; set it to Enemies Only to spare its teammates, as UCF Enemy Character Base does.
AdvancedReading what an enemy holds
The Equipment Manager answers on every machine. Get Combat Driver Instance returns the item driving combat, the weapon in hand or the Default Item, and Get Spawned Actor on it the actor showing it in the hand. On Combat Driver Changed fires when it changes. Equip Item puts an item in hand from Blueprint and Unequip Item takes one out, on the server; Equipment covers the rest.
MultiplayerWhere it runs
The Loadout runs on the server: it draws the starting items, picks the Item Sets row and drops the items at death there. The drawn items reach every machine through the Equipment Manager, and the dropped ones through their own replication, so every player sees the same sword in the same hand and the same sword on the ground.
C++C++
  • UUCFEnemyLoadoutComponent (UCFBridge) holds StartingItems, RandomStartingItems (FUCFEnemyStartingChoice: Items, Weight), ItemSets (FUCFEnemyItemSets: Item, CombatRole, ActionSet, ReactionSet) and OnItemDropped. It draws through UUCFEquipmentManagerComponent::EquipItem, or EquipItemIfFree for an enemy carrying a UUCFInventoryComponent, and writes the sets through SetProvidedActionSet and SetProvidedReactionSet.
  • AUCFEnemyCharacterBase creates Loadout, EquipmentManagerComponent, AnimManagerComponent, PhysicalReactionComponent and AnimEffectComponent, sets MeleeTraceComponent to UUCFCombatTraceComponent, and calls UUCFAbilitySystemReady::NotifyAbilitySystemReady from BeginPlay.
  • The drop at death runs UUCFDropStatics::DropEquipment per drawn item but the Default Item.

PageWhy
ItemsThe item definition and its fragments, the same for an enemy and the player.
EquipmentBody places, hold places and which drawn item drives combat.
Action SystemThe Action Set an Item Sets row hands the AI.
Reaction SystemThe Reaction Set an Item Sets row hands the AI.
Combat RolesThe roles an Item Sets row can name.
DefenseThe block and parry a held item lends, and posture.