-
Notifications
You must be signed in to change notification settings - Fork 56
Setup
Setting up the Target System plugin should be straightforward. This page intends to describe the project setup to enable targeting in your scene / level.
- Clone the repository inside your project's
Plugins
folder, or download the latest release and extract it into your project'sPlugins
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.
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 methodIsTargetable
which returns false by default, and can be overridden to plug-in your custom logic to prevent the targeting of this Actor (e.g., anIsAlive
state being true could causeIsTargetable
to return false; the health of the character being > 0 could causeIsTargetable
to return true, etc).
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
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.
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.
Once done, you can hit the Play button and see if it works.
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.
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).
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:
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.
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.
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:
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:
with the IsTargetable
method, which is a pure function that returns a boolean, defining whether or not this Actor should be targeted.
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:
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.