CrimsonCamera · Lesson 5 of 6
Data-Driven Lock-On
Before you start
- Completed: Your First Camera
- At least one lockable actor in the level
Chapters
How the pipeline works
Lock-on is built on Unreal's Gameplay Targeting System, so who can I lock is a data-driven, reorderable pipeline rather than hard-coded. The component runs a targeting request, the preset's tasks filter and sort candidates, the component picks the best result and a lock point on it, then it pushes UCrimsonCameraMode_LockOn to frame the target — and re-resolves each tick, breaking the lock if the target is gone, out of range, or out of sight.
1. Build a targeting preset
The preset decides who can be locked. It's a data asset — author it in the editor; there is no C++ step. Add tasks in order: selection, then filters, then a sort.
2. Create a lock-on config
UCrimsonLockOnConfig bundles the targeting preset, the lock-on camera mode class (make a Blueprint child of UCrimsonCameraMode_LockOn), an owner tag, and tunables like MaxLockDistance and SwitchDeadzone.
3. Add the components and lock points
Put a UCrimsonLockOnComponent on the player (assign the config), and a UCrimsonLockOnTargetComponent on each lockable actor. Fill the target's LockOnPoints with mesh sockets — several sockets make a boss's weak points cycle-able.
// Player pawn:LockOn = CreateDefaultSubobject<UCrimsonLockOnComponent>(TEXT("LockOn"));// Lockable actor (fill LockOnPoints in the Details panel):LockOnTarget = CreateDefaultSubobject<UCrimsonLockOnTargetComponent>(TEXT("LockOnTarget"));
4. Bind input
The lock-on component exposes Blueprint-callable actions. Bind your Enhanced Input to them.
LockOn->ToggleLockOn();LockOn->SwitchTargetInScreenDirection(RightStick); // X = right, Y = upLockOn->CycleLockPoint(+1);