Skip to content

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. Open your player character Blueprint (parent class Character or Pawn with a camera).
  2. Add ComponentAuto Aim Component.
  3. 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)

On FirstPersonCharacter, InputActionStartTargeting wires:

Input edgeCall
PressedStart Trace
ReleasedEnd 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.

While locked on, FirstPersonCharacter updates aim on Event Tick when a valid target exists:

  1. Get Hit Target (from Auto Aim Component).
  2. Get Auto Aim Interface on the hit actor — Branch on success (must implement BPI_AutoAim).
  3. Get Skeletal Mesh Component (interface call).
  4. Get Socket on the component → closest socket, or Override Socket Name when set.
  5. Get Socket Location on the skeletal mesh.
  6. Get World Location on the camera component.
  7. Set Look At Start Location (camera position).
  8. Set Look At Target Location (socket position).

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.

Bind on the Auto Aim Component in your character:

EventPayloadExample use
On Auto Aim StartedTrace hit resultLock-on reticle, SFX
On Auto Aim EndedHide reticle
On Auto Aim FailedError 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/).

  1. Open Blueprints/FirstPersonCharacter.
  2. Confirm Auto Aim Component is a child of the character.
  3. Leave component defaults unless you are testing a preset.
  1. InputActionStartTargeting Pressed → Auto Aim Component → Start Trace.
  2. InputActionStartTargeting Released → Auto Aim Component → End Trace.
  1. Event TickIs Aiming Now (or valid Hit Target) → Branch.
  2. True branch:
    • Get Hit Target
    • Get Auto Aim Interface → cast/check BPI_AutoAim
    • Get Skeletal Mesh Component
    • Get SocketGet Socket Location
    • Camera Get World LocationSet Look At Start Location
    • Socket location → Set Look At Target Location
  1. Select Auto Aim Component → Details → Events.
  2. Bind On Auto Aim Started — demo uses the trace hit result for gameplay feedback.
  3. Bind On Auto Aim Ended and On Auto Aim Failed for UI cleanup / error text.
  1. Open Map/AutoAimComponentExampleMap.
  2. PIE → hold Start Targeting on ThirdPersonCharacter_NPC → smooth pull toward socket.
  3. Release → On Auto Aim Ended.
GoalProperty
Lock from farther awayTrace Distance
Wider acquire coneTrace Size
Snappier pullInterp Speed ↑ or disable Use Smooth Aiming
Always aim at headOverride Socket Name = head socket
Stricter targetingCheck Line Of Sight on

Full list → Component reference.