# Lock-On Targeting in UE5: Switch Targets and Steer Attacks

> Souls-like lock-on for Unreal Engine 5 in Blueprint: lock the enemy you look at, switch with a flick, keep the camera on it, and turn each attack to the target.

Markdown version of https://rigbak.com/docs/universal-combat-framework/player/lock-on-targeting, a page of the Universal Combat Framework documentation. Link that page when citing it.

> Lock-on is three jobs: pick the right enemy when the button goes down, move to the next one with a flick of the stick, and make each attack land on the locked enemy instead of the air beside it. Universal Combat Framework does the first two in its Targeting component and the third in Attack Steering, which turns each attack toward its target and glides it into range.

Both parts run on Unreal Engine 5.6, 5.7 and 5.8, set up in Blueprint and data assets, in single player and multiplayer.

## The problem

A lock that only turns the camera leaves the fight half done. Attacks still play straight ahead, so a swing at an enemy a step to the side cuts the air, and a lunge at a close enemy runs into it. Switching targets needs its own rules too: which enemy a flick means, and when a lock should let go.

The Targeting component scores every enemy in range and holds the lock. Attack Steering reads the same target, so every attack turns to it, closes the gap and stops short of it.

---

## Try it in the demo

Play `LVL_UCF_Demo` and step onto the **Over Shoulder** style plate, whose arena holds six combo enemies. Press the middle mouse button (top face button on a gamepad) to lock the enemy nearest the screen's center, and move the mouse sideways (the right stick) to switch to the next. Attack: each swing turns to the locked enemy. Press the button again to let go.

---

## Lock-on on your own character

## Set it up (5 minutes)

1. **Make the enemies targetable**

   A character built on **UCF Character Base** is targetable already. On any other enemy, click **Add** and pick **UCF Targetable**, and set **Aim at Socket** to its chest bone, such as `spine_03` on the engine's mannequin.
2. **Give the player the lock button**

   Create an **Ability Set** (right-click in the Content Browser, **UCF > Actions > Ability Set**) and add a row: **Ability** `UCFLockOnAbility`, **Input Tag** `UCF.Input.LockOn`, **Input Action** `IA_UCF_LockOn`. On a character built on **UCF Character Base**, pick the set as **Starting Ability Set** in its Class Defaults. A character that keeps its own parent has no such slot: add the set to **Ability Sets to Grant** on its Default Item's **Equippable** fragment ([Character Setup](https://rigbak.com/docs/universal-combat-framework/player/character-setup)). The demo's `AbilitySet_UCF_Default` carries this row already, and the demo controller's `IMC_UCF_Default` maps `IA_UCF_LockOn` and the flick action `IA_UCF_Flick`; on a controller of your own, add a mapping context that maps both.

   In **AbilitySet_MyCharacter**, under Granted Gameplay Abilities > Index [ 0 ], set:

   | Property | Value |
   | --- | --- |
   | Ability | UCFLockOnAbility (replaces None) |
   | Input Tag | UCF.Input.LockOn (replaces None) |
   | Input Action | IA_UCF_LockOn (replaces None) |
3. **Pick a config that locks and switches**

   A character's targeting comes from its **Combat Style**, the **Style** on its **CombatComponent**; the demo player starts on `CombatStyle_UCF_OverShoulder`. Duplicate the style, set the copy as **Style**, and in the copy's **Targeting** fragment set **Targeting** to `TargetingConfig_UCF_Soulslike`. That config locks within 20 degrees of the screen's center, lets go past 25 m, and switches on the flick action `IA_UCF_Flick`. Set **Steering** to **Toward Target**.

   A character with no style takes the config in its **TargetingComponent**'s **Targeting Config** instead. One not built on **UCF Character Base** adds **UCF Combat**, **UCF Targeting** and **UCF Attack Approach** first ([Combat Styles](https://rigbak.com/docs/universal-combat-framework/player/combat-styles#what-a-style-sets-up)).
4. **Lock on and swing**

   Press Play, lock on, and attack from a few steps away and off to one side: the character turns to the locked enemy and closes in. The demo sword's montages carry the windows that steer an attack; a montage of your own needs one, which the next section adds.

---

## Make attacks land on the target

Attack Steering moves the character during the wind-up of an attack, through a window you mark on the montage:

| Your attack montage | Add |
| --- | --- |
| Animated on the spot | A **UCF Approach Window** across the wind-up, ending where the strike begins. The character turns to the target and glides into range. |
| Moving by root motion | The engine's **Motion Warping** notify state across the travel, with **Root Motion Modifier** **UCF Skew Warp** and **Warp Target Name** `UCFTarget`. The character needs a **Motion Warping** component. |

Off: Plays where it was aimed. The swing travels its own 160 cm and lands beside the target.

*Plays where it was aimed. The swing travels its own 160 cm and lands beside the target.*

Toward Target: Turns to the target and closes in, landing the stop distance short of it.

*Turns to the target and closes in, landing the stop distance short of it.*

Distance Only: Goes where the body faces, as animated, and stops short of the enemy its path runs into. The target off to the side is left alone.

*Goes where the body faces, as animated, and stops short of the enemy its path runs into. The target off to the side is left alone.*

*Seen from above, the character starting at the dashed circle and facing up the page. The dashed ring marks the stop distance around the body an attack stops short of; blue is where the attack ends and the arrow the way it faces.*

The attack stops the **stop distance** short of its target, 150 cm unless the style, the weapon or the window sets another, so it lands the blow instead of running into the enemy. **Keep Distance** also stops the attack short of other enemies in its path. [Attack Steering](https://rigbak.com/docs/universal-combat-framework/player/attack-steering) covers both windows and every distance setting.

While a lock is held, the style's **Attack Facing** turns the body to the locked enemy as each attack starts, whichever of **Aim**, **Movement** or **Lock Target** it is set to; **None** leaves the body as it was.

---

## Which enemy the lock picks

Without a lock, the Targeting component keeps a **soft target**: the best-scoring enemy in range, which attacks steer at. A lock press picks again with the config's **Lock Score Policies**, so a narrow cone around the screen's center can lock the enemy you are looking at over a nearer one off to the side.

A selection pass under the demo's Soulslike soft-target policies: Distance (Weight 2), View Angle (Weight 1) and Line Of Sight (Weight 0, a veto only). Each score is the weighted average of the two scoring policies; D sits behind a wall, so Line Of Sight drops it whatever it would score. The highest score is the target.

| Candidate | Distance | Distance score | Angle off view | View Angle score | Blend |
| --- | --- | --- | --- | --- | --- |
| A | 7.2 m | 0.64 | 8° | 0.91 | 0.73 |
| B | 4.9 m | 0.76 | 35° | 0.61 | 0.71 |
| C | 15.0 m | 0.25 | 2° | 0.98 | 0.49 |
| D | 5.7 m | 0.72 | 26° | 0.71 | vetoed |

*A selection pass under the demo's Soulslike soft-target policies: Distance (Weight 2), View Angle (Weight 1) and Line Of Sight (Weight 0, a veto only). Each score is the weighted average of the two scoring policies; D sits behind a wall, so Line Of Sight drops it whatever it would score. The highest score is the target.*

| Setting on the Targeting Config | Does |
| --- | --- |
| **Scan Radius** | How far the scan looks for enemies, in centimeters. |
| **Lock Score Policies** | How a lock press ranks enemies; a **View Angle** policy with its veto on and a tight angle makes a lock cone. Empty locks the soft target. |
| **Target Teams** | Which teams may be picked: **Enemies Only**, the default, leaves teammates out. |
| **Allow Lock** | Off turns lock-on off for this config. |

---

## Switch targets with a flick

Set the config's **Switch Input Action** to an Axis2D action that is active while locked, such as the demo's `IA_UCF_Flick`, and a flick of the stick or mouse moves the lock to the enemy that way. A stick resting on one side switches once; it has to come back before the next flick counts.

From Blueprint, **Switch Lock Target** switches in a direction you give, **Lock Target** locks an actor, **Clear Lock** lets go, and **On Lock State Changed** fires when a lock is taken, moved or let go ([Targeting](https://rigbak.com/docs/universal-combat-framework/player/targeting#switch-the-lock-with-a-flick)).

---

## When the lock lets go

A lock lets go when its enemy dies or stops being targetable, joins a team the config leaves out, or stays farther than **Lock Break Distance** for **Lock Break Grace Seconds** (1 second); a Lock Break Distance of 0, the default, turns the distance check off. Untick **Targetable** on an enemy, or call **Set Targetable**, as it goes down, and every character holding it lets go: a lock on it, a soft target on it, and an attack aiming at it.

---

## Keep the camera on the target

While a lock is held, the style's lock camera turns the view: **Camera, Lock Follow** aims at the target, and **Camera, Frame Both** keeps the character and the target in frame together ([Camera](https://rigbak.com/docs/universal-combat-framework/player/camera#the-camera-while-locked-on)).

To strafe around a locked enemy, set **Locked Rotation Mode** in the style's **Rotation** fragment, the body's turning while a lock is held, to **Camera Facing** or **Controller Desired**: the body turns with the camera, which the lock keeps on the enemy, so a sideways step circles it. The demo's Soulslike style faces where it moves, turns with the camera while locked (**Controller Desired**), and turns each attack toward the stick, or to the locked enemy while a lock is held (**Attack Facing** **Movement**) ([Combat Styles](https://rigbak.com/docs/universal-combat-framework/player/combat-styles#rotation-how-the-body-turns)).

<details>
<summary>Flick tuning (Advanced)</summary>

| Setting | Does |
| --- | --- |
| **Flick Activation Threshold** | How far, 0 to 1, the stick must be pushed to switch; 0.6 ignores drift. |
| **Flick Rearm Threshold** | How far it must come back before the next flick counts; 0.3. |
| **Switch Cooldown Seconds** | The shortest gap between two switches; 0.25. |
| **Flick Cone Half Angle Degrees** | How far off the flick an enemy may sit and still be picked; 60. |
| **Flick Direction Weight**, **Flick Proximity Weight** | Matching the flick's direction (0.35) against stepping to the enemy nearest the current lock on screen (0.65). |

</details>

<details>
<summary>Lock-on online (Multiplayer)</summary>

- Picking and locking run on the player's own machine, so the lock answers the press at once. The player's machine tells the server its target and lock whenever either changes, and an attack carries its own target.
- The server ignores a reported target beyond **Max Reported Target Range** (3000 cm), or one the character may not target.
- The Targeting Config, **Steering Mode** and **Attack Facing** do not replicate: set them on every machine, as a style's fragments on **Every Machine** do.
- Put the team on the pawn with a **UCF Team** component, since another player's machine reads a controller's team as none.

</details>

---

## Common questions

**Does it work with a gamepad?** Yes. The demo locks on the top face button and switches with the right stick.

**Can I have a soft lock without a lock button?** Yes. With no lock held, attacks steer at the soft target, the best-scoring enemy in range. The demo's Freeflow style plays this way, with no lock-on at all.

**Can I draw a marker on the locked enemy?** Yes. **Try Get Current Target Point** and **On Target Changed** feed a HUD marker; tick **Continuous Selection** on the config so a soft target's marker keeps up as the pick changes ([Targeting](https://rigbak.com/docs/universal-combat-framework/player/targeting#read-the-target-from-a-blueprint)).

**Can it lock onto something that is not a character?** Yes. Anything with an enabled **UCF Targetable** can be picked and locked, as long as the config's **Scan Object Types** include its collision type; **Aim at Socket** or **Aim at Component Tag** picks the point the lock aims at.

**Do I need C++?** No. Every step on this page is a component, an asset or a setting, and a score policy of your own is a Blueprint class.

---

## Related

| Page | Why |
| --- | --- |
| [Targeting](https://rigbak.com/docs/universal-combat-framework/player/targeting) | Every setting on the Targeting component and its config |
| [Attack Steering](https://rigbak.com/docs/universal-combat-framework/player/attack-steering) | Approach windows, warps, stop distances and Keep Distance |
| [Combat Styles](https://rigbak.com/docs/universal-combat-framework/player/combat-styles) | One asset for rotation, targeting, reach, movement and camera |
| [Camera](https://rigbak.com/docs/universal-combat-framework/player/camera) | The lock-on camera and the rest of the camera rig |

---

Previous page: [Combo System for UE5: Attack Chains, Input Buffering, Branches](https://rigbak.com/docs/universal-combat-framework/player/combo-system). Next page: [Parry, Block, Guard Break and Executions in UE5](https://rigbak.com/docs/universal-combat-framework/player/parry-block-executions)
