-
Notifications
You must be signed in to change notification settings - Fork 16
2. LockOnTargetComponent Overview
Note It's assumed that you've already read the Core Concepts.
The corresponding header file:
LockOnTargetComponent.h
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.
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.
LockOnTargetComponent uses a TargetHandler for finding and maintaining a Target.
LockOnTargetComponent has some strict requirements that must be met in order for the Target to be captured:
- Target isn't ourselves.
- TargetComponent is valid.
- TargetComponent contains at least one Socket.
- TargetComponent can be captured.
- We haven't captured this Target.
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. |
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.
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). |