Skip to content
Mickael Daniel edited this page Jun 18, 2020 · 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.

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 on this specific Actor. It has a single method IsTargetable which return false by default, and can be overridden to plug-in your custom logic to prevent the targeting for this Actor (like a IsAlive state, or if the health of this character is > 0).

1. Attach the TargetSystemComponent

The first step is to attach the TargetSystemComponent UActorComponent to your Player Character. In the Third Person Blueprint template, you can do so with ThirdPersonCharacter Blueprint.

Add the component to your Blueprint

add_component

added_component

Options

options

  • float MinimumDistanceToEnable: The minimum distance to enable target locked on.
  • TSubclassOf<AActor> TargetableActors: The AActor Subclass to search for targetable Actors.
  • TSubclassOf<UUserWidget> TargetLockedOnWidgetClass: The Widget Class to use when locked on Target. If not defined, will fallback to a Text-rendered widget with a single O character.
  • float TargetLockedOnWidgetDrawSize: The Widget Draw Size for the Widget class to use when locked on Target.
  • float BreakLineOfSightDelay: The amount of time to break line of sight when actor gets behind an Object.
  • float StartRotatingThreshold: Lower this value is, easier it will be to switch new target on right or left.
  • bool ShouldControlRotationWhenLockedOn: Whether or not the character rotation should be controlled when Target is locked on. If true, it'll set the value of bUseControllerRotationYaw and bOrientationToMovement variables on Target locked on / off. Set it to true if you want the character to rotate around the locked on target to enable you to setup strafe animations.
  • FVector TargetLockedOnWidgetRelativeLocation: The Relative Location to apply on Target LockedOn Widget when attached to a target.

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

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 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 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, it 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, usually "Turn" if four 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. Lower this value is, easier it will be to switch to new target on 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 another state.

First, you should add the interface to the TargetableActors:

interface_add

interface_added

In this setup, this is simply done on the same ThirdPersonCharacter blueprint, because that's the Actor we're targeting in this demo.

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 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.

Clone this wiki locally