Add lock-on to your character
Reproduce how FirstPersonCharacter drives the component in the demo project. Adapt input names to your Enhanced Input or legacy setup.
flowchart TD
Press["InputActionStartTargeting Pressed"] --> ST["Start Trace"]
ST --> Hit{Trace hit pawn?}
Hit -->|Yes| Started["On Auto Aim Started"]
Hit -->|No| Failed["On Auto Aim Failed"]
Started --> Tick["Event Tick"]
Tick --> GAI["Get Auto Aim Interface"]
GAI --> Mesh["Get Skeletal Mesh Component"]
Mesh --> Socket["Get Socket → Socket Location"]
Socket --> Set["Set Look At Start / Target Location"]
Release["InputActionStartTargeting Released"] --> ET["End Trace"]
ET --> Ended["On Auto Aim Ended"]
Prerequisites: Migrated assets and at least one NPC with BPI_AutoAim.
1. Add the component
Section titled “1. Add the component”- Open your player character Blueprint (parent class Character or Pawn with a camera).
- Add Component → Auto Aim Component.
- Start with demo defaults:
- Trace Distance
3000 - Trace Size
100 - Use Smooth Aiming on, Interp Speed
10 - Update Every Frame on
- Types To Trace — Pawns (
ObjectTypeQuery3)
- Trace Distance
2. Start and stop tracing
Section titled “2. Start and stop tracing”On FirstPersonCharacter, InputActionStartTargeting wires:
| Input edge | Call |
|---|---|
| Pressed | Start Trace |
| Released | End Trace |
Start Trace runs a box trace from the camera forward vector. On success it sets Hit Target and broadcasts On Auto Aim Started (trace hit result). On failure, On Auto Aim Failed runs.
3. Update look-at every frame
Section titled “3. Update look-at every frame”While locked on, FirstPersonCharacter updates aim on Event Tick when a valid target exists:
- Get Hit Target (from Auto Aim Component).
- Get Auto Aim Interface on the hit actor — Branch on success (must implement BPI_AutoAim).
- Get Skeletal Mesh Component (interface call).
- Get Socket on the component → closest socket, or Override Socket Name when set.
- Get Socket Location on the skeletal mesh.
- Get World Location on the camera component.
- Set Look At Start Location (camera position).
- Set Look At Target Location (socket position).
4. Optional — free look and cancel
Section titled “4. Optional — free look and cancel”When Enable Free Looking is on, forward Turn / Look Up axis values to:
- Free Look (
Pitch Axis,Yaw Axis) - Try Cancel Auto Aim From Input (
In Axis Value)
Demo defaults: Input Time To Cancel 0.2 s, Free Look Distance 10.
5. Bind aim events
Section titled “5. Bind aim events”Bind on the Auto Aim Component in your character:
| Event | Payload | Example use |
|---|---|---|
| On Auto Aim Started | Trace hit result | Lock-on reticle, SFX |
| On Auto Aim Ended | — | Hide reticle |
| On Auto Aim Failed | Error message string | “No target” UI |
Worked example — FirstPersonCharacter pattern
Section titled “Worked example — FirstPersonCharacter pattern”This is the exact flow in the shipped demo (paths under Content/AutoAimComponent/).
Component setup
Section titled “Component setup”- Open Blueprints/FirstPersonCharacter.
- Confirm Auto Aim Component is a child of the character.
- Leave component defaults unless you are testing a preset.
Input wiring
Section titled “Input wiring”- InputActionStartTargeting Pressed → Auto Aim Component → Start Trace.
- InputActionStartTargeting Released → Auto Aim Component → End Trace.
Per-tick look-at (Event Graph)
Section titled “Per-tick look-at (Event Graph)”- Event Tick → Is Aiming Now (or valid Hit Target) → Branch.
- True branch:
- Get Hit Target
- Get Auto Aim Interface → cast/check BPI_AutoAim
- Get Skeletal Mesh Component
- Get Socket → Get Socket Location
- Camera Get World Location → Set Look At Start Location
- Socket location → Set Look At Target Location
Event bindings
Section titled “Event bindings”- Select Auto Aim Component → Details → Events.
- Bind On Auto Aim Started — demo uses the trace hit result for gameplay feedback.
- Bind On Auto Aim Ended and On Auto Aim Failed for UI cleanup / error text.
- Open Map/AutoAimComponentExampleMap.
- PIE → hold Start Targeting on ThirdPersonCharacter_NPC → smooth pull toward socket.
- Release → On Auto Aim Ended.
Tune feel
Section titled “Tune feel”| Goal | Property |
|---|---|
| Lock from farther away | Trace Distance ↑ |
| Wider acquire cone | Trace Size ↑ |
| Snappier pull | Interp Speed ↑ or disable Use Smooth Aiming |
| Always aim at head | Override Socket Name = head socket |
| Stricter targeting | Check Line Of Sight on |
Full list → Component reference.