Configure the Target Lock
Last modified: 29 December 2024The Target Lock Ability helps with camera focus, precision and add visual indicators to a target. This system uses Unreal Engine's Gameplay Targeting System to collect targets.
Create a new Targeting Preset. It will be used for the target selection.
Add the Camera Selection Task. You can use its default values or adjust them as you like.
Add the AOE Selection Task. Use a Sphere shape, add Pawn and World Dynamic as Collision Object Types, set it to ignore the source actor and instigator, and a radius of 1600.
Add the Actor Class Filter Task. Set your base Character Class as the Required Actor Class Filter, or adjust these filters to match your character hierarchy.
Add the Facing Filter Task. Set the maximum angle to 60, or any other value that makes sense to you.
Add the Dead Filter Task.
Add the Sort By Distance Filter Task.

note
Debugging Targeting Presets
When in doubt, start your Targeting Presets with a valid AOE Selection Task, making sure to ignore the source actor and instigator.
Then, add an Actor Class Filter, valid for your enemy hierarchy. This should be a good starting point to create a valid Targeting Preset.
You can also check the Debugging Page to learn more about the Gameplay Targeting System's debug features.
Create a new Gameplay Ability using
CombatAbility_TargetLock
as the base class.Set the Targeting Preset that was created in the step above.
Disable Move to New Targets for now, but feel free to explore this if you'd like.
Set the Distance Threshold to 1600, or any other value that makes sense to you. This will disengage from the target, if the distance from the avatar exceeds this value.
Add this Gameplay Ability to the list of Default Abilities added to the player.

Create a new Input Action for the Target Lock input. Add a Pressed trigger to it.
Add the new Input Action to your Input Mapping Context asset, mapping it to an appropriate key.
Create a new Input Handler or add one directly to your Input Setup, using the Activate Ability by Tags as base.
Add
Ability.TargetLock
to the Ability Tags.Set Toggle Activation, so the ability is activated and then deactivated on input.
