Skip to content
andrewcreekmore edited this page Jun 8, 2022 · 6 revisions

Setting up the Target System plugin should be straightforward. This page intends to describe the project setup to enable targeting in your scene / level.

Setting up the Plugin as a Project's plugin

  • Clone the repository inside your project's Plugins folder, or download the latest release and extract it into your project's Plugins folder.
  • Put Config/DefaultInput.ini from the plugin folder inside your project's config folder. If your project already have this .ini file, merge it into yours (this step is only required if you wish to use the provided example Test map within the plugin, it just ensures the Inputs from Third Person Template are enable for your project. If your project already starts off from the Third Person Template, or if you don't wish to use the provided example Test map, you can skip this step)
  • Regenerate Visual Studio project files and build your projects.
  • Launch the project, and enable plugin content viewer ("Show Plugin Content" in View Options dropdown). This will show contents of the plugin in your content browser.
  • Open /TargetSystem/Maps/TargetSystemTestMap map to see it in action.

Setup

To make things easier, you should start your project with a Third Person Blueprint template. That being said, setting up this plugin to work on an existing project should be the same process and as easy to setup.

The plugin comes with 2 Classes:

  • TargetSystemComponent: This is the main class, which is an Actor Component and should be attached to your PlayerCharacter blueprint.
  • TargetSystemTargetableInterface: A simple interface you can use on your targetable actors to enable (or prevent) the targeting of this specific Actor. It has a single method IsTargetable which returns false by default, and can be overridden to plug-in your custom logic to prevent the targeting of this Actor (e.g., an IsAlive state being true could cause IsTargetable to return false; the health of the character being > 0 could cause IsTargetable to return true, etc).

1. Attach the TargetSystemComponent

The first step is to attach the TargetSystemComponent UActorComponent to your Player Character's Blueprint. For example, if you used the Third Person Blueprint template, you would attach this component to the ThirdPersonCharacter Blueprint. Click "add component" and search for Target System, then click to select it. It should now appear in your Player Character's list of components, underneath CharacterMovement.

Add the component to your Blueprint

add_component

added_component

Once done, you can click on the TargetSystem component in the components list and adjust options to your liking. Check the Configuration page for more information on these.

image

2. Setup a bind to Target a new Actor

Once the TargetSystemComponent is attached, you can setup a new bind to call the TargetActor function. This is the main function to call to target the nearest targetable actor (as defined by TargetableActors option) from your main character.

tab_to_target_actor

Once done, you can hit the Play button and see if it works.

target_lockon_default

3. Setup the Locked On Widget

The Locked On Widget is the visual icon that appears over the targeted actor, indicating what the Player Character is currently locked on to. By default, the TargetLockedOnWidgetClass is set to the UMG Widget included in this plugin. You can override and extend this Widget or use a custom one.

To change the target lock on widget, simply define a new Widget for TargetLockedOnWidgetClass option.

target_lockon_widget_select

Added in 1.25.0, you can specify a Bone name, with LockedOnWidgetParentSocket, for the widget to be attached on if the Actor has a Mesh component. It is set to spine_03 by default, but you can change it to any valid bone. If set to NONE, the widget will be attached to the Root component instead of the Mesh component (or if it doesn't have a Mesh, in which case the LockedOnWidgetParentSocket option has no effect).

If the relative location of the widget needs to be changed, you can do so with the TargetLockedOnWidgetRelativeLocation vector option, namely with the Z axis, to make it lower or higher relative to the parent component widget (RootComponent or Mesh).

4. Switch Targets with Axis Input

Switching targets can be done with Axis input, either with mouse or gamepad input. To do so, you need to bind the "Turn" or "TurnRate" input action for both mouse / gamepad (or only the ones that you're interested in switching targets with) with the TargetActorWithAxisInput method which takes AxisInput as a parameter:

target_actor_with_axis_input

Doing this should allow you to switch targets, either to the right or left, based on Mouse or Gamepad stick axis inputs.

For Gamepads, the Axis value only goes to either -1.0 or 1.0, which might be too low for it to exceed your configured StartRotatingThreshold. In this case, you should use two different Input events for mouse and gamepad (In ThirdPerson template, typically "Turn" is for the mouse and "TurnRate" is for the gamepad). For the TurnRate input, you should multiply the Axis value by a set amount to allow it to reach your StartRotatingThreshold.

target_system_gamepad_setup

Note that the StartRotatingThreshold option (by default set to 1.5) is used to determine when the switching should happen. The lower this value is, easier it will be to switch to a new target on the right or left.

5. Setup TargetSystemTargetableInterface

This step is optional, but lets you further define when and how an Actor should be targetable. It can be handy to prevent the Actor from being targeted if it is dead, or depending on any custom state.

First, you should add the interface to the TargetableActors you want to allow the Player Character to target, such as an enemy. To do so, go to that Actor's Blueprint and choose Class Settings, which will change the right-hand Details pane. In this pane, find Interfaces, click Add, and search for and choose TargetSystemTargetableInterface:

interface_add

interface_added

In our example, this is being done on the same ThirdPersonCharacter blueprint, because that's the Actor we're targeting in this demo - but typically speaking, this interface is added to non-player characters such as enemies.

This interface lets you implement a single method: IsTargetable

By default, on the left, under the My Blueprint section, you should see:

interface_functions

with the IsTargetable method, which is a pure function that returns a boolean, defining whether or not this Actor should be targeted.

interface_is_targetable

By default, it returns false making this actor no longer targetable.

You can and you should implement this method with your own custom logic. For the purpose of this guide, we're going to bind this return value with a simple boolean that represent the IsAlive state of this actor:

inteface_is_targetable_with_alive_bool

Then, setting this IsAlive boolean to true or false in your gameplay logic should determine if this actor is an actor that can be targeted.