Build Your First Combo

Documentation Unreal Engine Player Combat Tutorial

Build a sword with a three-hit combo from two assets of your own, an action graph and an item, and the demo's animation, mesh and keys. The demo's Item_UPC_Sword is the finished version.


Set it up

15 minutes
  1. 1

    Create the graph and its three hits

    Content Browser
    ▸ Content
    Right-click in the Content Browser, UPC, Actions, Action Graph.
    Open it: ROOT is the character standing idle. Right-click the canvas, Add Action Node, three times, and set each card's Node Name, then the Montage and Section Name of its Play Montage payload, the part of the card that plays the move:
    Node NameMontageSection Name
    Light 1AM_UPC_Sword_Combo0
    Light 2AM_UPC_Sword_Combo1
    Light 3AM_UPC_Sword_Combo2
    Tick Show Plugin Content in the picker's view options to list it.
  2. 2

    Wire the hits into a chain

    Drag from ROOT's right edge to Light 1. On the router that appears (the small card on the wire, one row per input it takes), set the entry's Input Tag to UPC.Input.LightAttack (Fires On: Input Pressed). Wire Light 1 to Light 2 and Light 2 to Light 3 the same way, then Compile and save.
    ROOT
    UPC.Input.LightAttack
    Light 1
    AM_UPC_Sword_Combo
    UPC.Input.LightAttack
    Light 2
    AM_UPC_Sword_Combo
    UPC.Input.LightAttack
    Light 3
    AM_UPC_Sword_Combo
    Zoom -1
    Three cards, each playing one section of the same montage, and a light attack press leading from each to the next. Nothing leads on from Light 3, so the character returns to ROOT when it ends.
  3. 3

    Create the item

    Content Browser
    ▸ Content
    Right-click in the Content Browser, UPC, Items, Item Definition.
    Open Item_MySword and set Slot Tags to UPC.Slot.Weapon.Sword, so the demo belt's weapon slot takes it. Under Fragments, press +, pick Visuals and set Mesh to SM_UPC_Sword.
  4. 4

    Make it drawable, with its moves and its key

    Add an Equippable fragment and fill it in as below, adding one Input Mappings row for the key. Give the Hold Places row UPC.Place.Main (the right hand) the demo sword's grip: Offset Location -9.86, 2.70, -0.45, Rotation Y -90.
    Item_MySword
    ▾Fragments
    Index [ 1 ]None
    Drawing the item adds its keys and graph; putting it away takes both back.
  5. 5

    Give the blade a hit volume

    Add a Trace Sockets row. Its sockets read TraceStart and TraceEnd, on SM_UPC_Sword's guard and tip.
    Item_MySword
    ▾Trace Sockets
    IDNone
    Source Component TagNone
    ShapeSphere
    A capsule from TraceStart to TraceEnd, swept while a trace window plays.
    The ID must read Blade, the name each trace window sweeps; UPC.ItemMesh tags the item's mesh in the hand.
  6. 6

    Put it in the hands and swing

    Add Item_MySword to Starting Items on the InventoryComponent of BP_UPC_Character (Demo/Characters/Player), or of your copy once it is the game mode's Default Pawn Class (see Getting Started). Play LVL_UPC_Demo: the belt draws the sword from slot 1. At a training dummy, click to swing Light 1, then click during Light 1 and again during Light 2: each plays the next hit as that swing ends.

When the blade hits

Each section of AM_UPC_Sword_Combo carries a UPC Melee Trace Window naming Blade, the only stretch where the blade hits.
AM_UPC_Sword_Combo
0.0
0.25
0.5
0.75
1.0
1.25
1.5
1.75
2.0
Sections
0
1
2
Trace
Melee Trace: Blade
Melee Trace: Blade
Melee Trace: Blade

How the hits chain

Within the combo. With no UPC Action Window on the montage, a click during a swing waits for the section's end, then plays the next hit (When No Window Is Authored: At Completion). A UPC Action Window lets a click cut in sooner (Action Graph).
Restarting. Light 3 has no next move, so a click restarts through ROOT only in Light 3's last 0.35 seconds: a click 0.2 seconds before the end restarts the combo, one 0.5 seconds before is forgotten. That limit is the graph's Held Input Restart Window (select empty canvas in the graph editor), and it applies to any waiting press.

Use your own animations

  1. Make a montage: right-click the animation, Create, Create AnimMontage. One per hit, or one with an unlinked section per hit, as the demo does.
  2. Make a damage config: UPC, Damage and Defense, Damage Config. Its Damage starts at 10.
  3. Add a trace window to each swing: Add Notify State..., UPC Melee Trace Window, across the frames where the blade connects, with Socket IDs Blade and your Damage Config.
  4. Point each node at its Montage and Section Name.

Use your own mesh

In your sword's static mesh, add the sockets TraceStart above the guard and TraceEnd at the tip (Socket Manager). Equipment shows how to find the grip Offset.

The demo sword
Demo assetAdds
AG_UPC_SwordTwo heavy attacks, a guard that cuts in from any hit, a 0.25 second Recovery after a hit with no press waiting, and the shield's moves while a shield is drawn. Aliases wire the heavy and the guard to all three hits (Action Graph Editor).
Item_UPC_SwordStowable (it hangs on the back when put away), Guard (block and parry), Swing Trail, and the Item Actor Class BP_UPC_Sword, whose mesh tag WeaponMesh its Trace Sockets row names.
Patterns walks through the parry, the guard and the demo's other moves.

Debug it

UPC.Debug.Actions 1            // Each character's node, window and waiting press
UPC.Debug.Melee.DrawTracing 1  // The swept shapes, drawn in the world
C++Grant a graph or an item from code
  • UUPCInventoryComponent::AddItemDefinition(UUPCItemDefinition*, int32 StackCount = 1) adds an item on the server; the belt takes it as it takes Starting Items.
  • UUPCEquipmentManagerComponent::EquipItem(UUPCItemDefinition*, UUPCInventoryItemInstance* = nullptr) draws an item on the server, with no belt.
  • UUPCActionGraphComponent::SetActionGraph(UUPCActionGraphAsset*) hands a character a graph with no item, for a creature whose moves never change.
AdvancedTroubleshooting
The sword swings, or not, and nothing is hit
  • No sword in the hand: the item lacks an Equippable fragment, the belt has no slot whose Filter its Slot Tags match, or Starting Items does not list it.
  • The press does nothing: the Input Mapping's Input Tag differs from the transition's, the Input Mapping Context lacks the Input Action, or the graph is not compiled. UPC.Debug.Actions 1 shows ROOT.
  • The swing hits nothing: no volume named Blade registered. The row's ID differs, its Source Component Tag names a component nothing carries, the mesh lacks TraceStart or TraceEnd, or the sword sits in a place other than the first of its Hold Places, which registers Blade_Off. The Output Log names a refused row.