# Bot and Combat: Lock On to a Sensed Target

> For the complete documentation index, see [llms.txt](llms.txt).

Make a guard lock on to the player it selects through perception. When the guard forgets the player, it should release the lock and return to its search or patrol. Start with a [guard that sees the player](bot-first-steps.html) and a [combatant with a Target Manager](cbt-first-steps.html).

Procedure: Pass the guard's selected target to Combat

1. Grant the guard a `CombatAbility_TargetLock` ability and set up the player as a viable target using [Lock On and Align an Attack](cbt-guide-target-lock.html). Check that the guard's tree selects a perception candidate when it sees the player.

2. Open the guard's `NinjaBotAIController` Blueprint. Set Perception Target Acquired Event Tag to `Combat.Event.Target.Acquired` and Perception Target Dismissed Event Tag to `Combat.Event.Target.Dismissed`. Compile and assign it as the guard's AI Controller Class.

The controller sends the acquired event to the guard's ability system. The guard is the instigator and the selected player goes in both Target and Optional Object. Target Lock reads Optional Object and checks `IsViableTarget`. A guard that only locks on through perception can leave the ability's targeting preset empty. If your own AI sends this event, put the selected actor there too.

To play an alert bark, override `HandlePerceptionCandidateSelected` on the controller Blueprint. Call the parent so it still sends Combat's event. Use `HandlePerceptionCandidateCleared` to stop the alert. In a C++ controller, override the corresponding `_Implementation` methods and call `Super`. For a marker that should appear only after Combat accepts the target, bind to `BindToCombatTargetChangedDelegate` on the Target Manager.

## Try It in Play

Walk into sight and compare the actor selected in the AI debugger with the guard's combat target. They should be the same player. Break sight and wait for the guard's configured memory to expire. The lock should clear when the candidate is dismissed. If the AI selects the player but Combat never locks, check the ability grant, the acquired event tag, and the actor in Optional Object.

