Skip to content

2. LockOnTargetComponent Overview

J1blCblu edited this page Oct 31, 2023 · 25 revisions

Note It's assumed that you've already read the Core Concepts.

Player Input Overview.

The corresponding header file: LockOnTargetComponent.h

image

General Overview

LockOnTargetComponent gives a locally controlled APawn the ability to find and store a Target.
The Target can be controlled directly by the component or through an optional TargetHandler.
Independent logic such as widget attachment, camera focusing and etc. is encapsulated inside LockOnTargetExtensions.

image

LockOnTargetComponent provides the following base methods:

Method Description
SetCanCaptureTarget() Sets the new bCanCaptureTarget state. Clears the Target if necessary.
IsTargetLocked() Is any Target locked.
GetTargetComponent()
GetTargetActor()
GetCapturedSocket()
Returns corresponding data about the captured Target.
GetTargetingDuration() Returns the targeting duration in seconds.

Use SetLockOnTargetManual/ByInfo(), ClearTargetManual() and SwitchTargetManual() to force Target control.

TargetHandler

LockOnTargetComponent uses a TargetHandler for finding and maintaining a Target.

image

LockOnTargetComponent has some strict requirements that must be met in order for the Target to be captured:

  1. Target isn't ourselves.
  2. TargetComponent is valid.
  3. TargetComponent contains at least one Socket.
  4. TargetComponent can be captured.
  5. We haven't captured this Target.

image

TargetHandlerBase is the base abstract TargetHandler that provides the following interface:

Method Description Notes
FindTarget() Finds and returns a Target to be captured by LockOnTargetComponent. [required]
CheckTargetState() Checks the Target state between updates. [optional]
HandleTargetException() Processes an exception from the Target, e.g. Target is destroyed. [optional]

LockOnTarget provides WeightedTargetHandler with the following features:

  • Sorting to find the most relevant Target.
  • Auto find for a new Target.
  • Target switching in screen space.
  • Distance check.
  • View check.
  • Line of Sight check.
  • Debugger.

LockOnTargetComponent provides the following methods to manage TargetHandler at runtime:

Method Description
GetTargetHandler() Returns the current TargetHandler.
SetTargetHandlerByClass() Creates and returns a new TargetHandler from class.
ClearTargetHandler() Destroys the current TargetHandler.

Extensions

As mentioned earlier, LockOnTargetComponent is just a storage for the captured Target, other optional features are implemented inside extensions. LockOnTarget provides some base extensions such as Pawn rotation, Target indication and others.

image

LockOnTargetComponent provides the following methods to manage extensions at runtime:

Method Description
FindExtensionByClass() Finds an extension by class. Complexity O(n).
AddExtensionByClass() Creates and returns a new extension by class. Complexity amortized constant.
RemoveExtensionByClass() Destroys an extension by class. Complexity O(n).
GetAllExtensions() Returns all extensions.
RemoveAllExtensions() Destroys all extensions. Complexity O(n).
Clone this wiki locally