🚀 Spring Sale is live! 🚀 Don't miss your chance to get all my products at 30% OFF!  

Get it!

Target Targeting System

Introduction

GCS_TargetingSystemComponent utilizes the built-in "Gameplay Targeting System" from UE5.2 to implement the search, filtering, sorting of potential targets, and the target locking logic.

Therefore, ensure that your project has this plugin enabled:

目标定位系统.001

Also, refer to the official documentation for a general understanding of it.

Targeting System Component

Once you add GCS_TargetingSystemComponent to your character, you can configure the following default properties:

目标定位系统.002
  • AutoUpdatePotentialTargets: When checked, this component will search for potential targets based on the component's tick frequency and store them in PotentialTargets.
  • TargetingPreset: You can specify a preset to search for potential targets.

Default Targeting Preset

GCS provides a default preset called TP_GCS_Default. Its configuration is as follows:

目标定位系统.003

The functionality it implements is: it detects targets of the pawn collision type within a 20-meter spherical range and sorts them by distance from closest to farthest, filtering only enemy factions and characters with the "Death" tag or those that are already dead.

Performance Consideration: When your game has a large number of Actors, performing spherical detection for potential targets on each Actor can be performance-intensive. You can alleviate performance pressure by adjusting the tick frequency of the TargetingSystem component.

In practical development, you may need a separate system to cache references to all combat Actors in the scene and query from there, which can reduce the performance impact of collision detection.

Gameplay Integration

Target Locking/Switching

The targeting system component provides the following API to allow you to select and switch targets. You can find how to bind this functionality to the input system in the content provided by GCS.

目标定位系统.004

Additionally, you can respond to target locking and unlocking through events. For example, when a target is locked or unlocked, I might switch to a different camera mode, as shown below.

目标定位系统.005

Note: If you lock onto a target that is no longer part of the PotentialTargetActors, it will automatically unlock.

Query API

目标定位系统.006

You can query an actor's potential targets at any time through PotentialTargets, which can be useful when integrating with the AI system.

Gameplay Targeting System Extension

The Gameplay Targeting System is an official data-driven method for target acquisition requests. You can create different TargetingPresets and combine various TargetingTasks within them to achieve simple to complex target acquisition, filtering, and sorting.

Basic Usage

目标定位系统.007
目标定位系统.008

Among the usages provided by the Gameplay Targeting System, the following two are the most common:

The second usage is more flexible, allowing you to pass more information to the TargetingSourceContext.

You can find a wealth of related usages in the demo provided by GCS. These are integrated into the bullet system and weapon system, so in most cases, you only need to focus on how to configure the TargetingPreset.

Built-in Targeting Tasks

Here are some commonly used TargetingTasks built into GCS.

GCS: Selection Task Trace

This task is the primary means of acquiring one or more targets. It extends the default Targeting Selection Task Trace provided by the system, allowing for various collision detection methods.

目标定位系统.009

Dynamic Detection Level

A dynamic level system is implemented, allowing you to obtain the detection level externally during targeting and dynamically adjust the shape, size, radius, etc., of collision detection. This requires the SourceObject in the TargetingContext to implement the GCS_TargetingSourceInterface.

In GCS, collision trace instances implement the TargetingSourceInterface, and the activation time of the collision trace instance serves as the trace level. This means you can dynamically adjust the trace shape used by this SelectionTask based on the activation time of the collision trace instance.

GCS: Filter Task Tag Requirements

This task is used to filter out certain actors from the already selected targets.

目标定位系统.010

Here, you can edit the tag query named QueryMushMatch. If an actor meets this query, it will be filtered out from the target results. You can also check "Invert" to reverse the results of the tag query.

GCS: Filter Task Affiliation

目标定位系统.011

You can check to detect enemies, neutral targets, or allies.

  • LookCombatTeamAgentInterface: If checked, it will use Faction/Team Integration to determine affiliations.
  • LookCombatTeamAgentInterfaceInComponents: If checked, it will query for implementations of GCS_CombatTeamAgentInterface in the Actor's component tree.
  • LookGenericTeamAgentInterface: If checked, it will determine the affiliation using the team interface from UE's AIModule if the above two methods fail. However, the built-in interface can only be used through C++.

Targeting Source Interface

When customizing a Targeting Selection Task, you need to pass external information to the Task's internals through TargetingSourceContext. Additionally, you want to easily access external information from within the Task without worrying about the specific external object type.

GCS solves this problem through the GCS_TargetingSourceInterface.

目标定位系统.012

Usage

The built-in SelectionTask GCS: Selection Task Trace works well with this interface. You just need to pass an object implementing GCS_TargetingSourceInterface through SourceObject to the SelectionTask.

目标定位系统.013

Other Uses

Suppose you are creating a bomb that, when it explodes, will bomb all targets within a certain range over a 3-second period.

You can make the bomb implement the targeting source interface and use a sphere SelectionTask to acquire targets within the radius. As the explosion time progresses from 0 to 3 seconds, the radius of the sphere will gradually expand to its maximum range.