In this post we will learn how to implement a targeting enemy system similar to the one used in “Dark Souls” games.
This tutorial will use Blueprints and it will contain:
- Switching the mode between targeted/un-targeted enemy.
- Create a visual indicator above the enemy that will be displayed in target mode.
- Implement Camera behaviour for target mode.
Note: This tutorial is made in Unreal Engine 4.10.4 and it use Third Person new Blueprint project.
New project Window
Open the Content Browser and right click on the ThirdPersonCharacter blueprint then select Duplicate from drop-down menu.
After that name the new blueprint “Enemy_BP“.
 Duplicate the ThirdPersonCharacter blueprint. To do that you can also select a blueprint and press Ctrl + W
Open the Enamy_BP and remove Gamepad input, Mouse input,
Touch input and on the left side of the blueprint in Components remove CameraBoom and Follow Camera in your Enamy_BP:
Create Target Visual
Now our project is set-up and ready to work.
The next step is to create visual object that will show above the enemy when the target mode is on.
Press Add Component on the left-hand side of the Enemy blueprint then add a Sphere and name it TargetVisual.
 Drag a Sphere from the Components tab
Make the TargetVisual a child object of a Mesh by dragging it on the Mesh.
 Target visual is a child
Click on the TargetVisual, then on the right-hand side of the blueprint find Sockets and then in the Parent Socket press the magnify glass icon to find a spine_01.
Note: Parent Socket will make our TargetVisual object move with the bone we selected; in this case it’s spine_01,
also more information about sockets can be found HERE.
 Details of our Target Visual
After parenting socket you should notice the weird position of TargetVisual, to fix this go to Transform and in location set X, Y and Z to 0, 0, 0.
It will move the TargetVisual to the spine_01 location.
From here you can adjust your TargetVisual to location that suit your personal need in this case TargetVisual will appear above the enemy.
 Vieport view
Last important step we have to do in setting up our TargetVisual hidden in game.
To do this, go to details tap and type “hidden” then in Rendering make sure you mark Hidden in Game.
 Set rendering to hidden
Now when your TargetVisual is ready, save the Enemy_BP and go back to the Content Browser.
In the Content Browser, right click then select Blueprints -> Blueprint Interface and name it Game_BPI. To make long story short, interface is usually used when many classes need to implement certain behaviour. See the documentation to learn more Docs.
 Add a new Blueprint Interface
Open the Game_BPI and add a new function called TargetLockON then save it and go back to the Enemy_BP.
 Function view with newly created TargetLockON
Once Enemy_BP is opened press on the Class Settings icon to will open an extra tab on the right-hand side of the blueprint.
 Class settings
In Class Settings tab find Interfaces area and then click on the Add button to add our Game_BPI.
 Hook-up our new blueprint interface
Trigger Target Visual enemy blueprint logic
In Enemy_BP find some free space and add all the necessary components as shown in picture :
 Set Hidden in Game
This event will be used to switch our TargetVisual object On or Off.
Blueprint can be inherited like C++ classes. Back in our Content Browser right click to add a new Blueprint. It will open a new window called “Pick Parent Class“. Then below All Classes type gameinstance.
Select it and add it while using the name “Zone_GI”
 Type the “GameInstant” to fast-find the parent class you are looking for.
Once it’s added, it should look like the example shown in the picture :
 Zone_GI in the Content Browser
Open it up and add a variable called TargetPosition then press on the closed eye icon next to a newly created TargetPosition variable. Now the eye should be opened.
It will make the variable public so you can get access to it form our Enamy_BP.
Click on the TargetPosition and on the right side of this blueprint change variable type to Vector.
Save and compile blueprint.
 If you don’t want to lose your progress, remember to often save your blueprints. If your logic doesn’t work, maybe you can check if the bp was compiled
Press on the Edit > Project Settings… then select Maps & Modes and change or add a game instance. (Zone_GI)
 Project settings view
Send Enemy Target Location
Go back to the Enemy_BP and create a new function called SendTargetLocation then make it look like picture below.
This function will return enemy location, that we will be used later to move our player camera around.
 Enemy_BP – Send target location
One more thing that we need to do is adding our function to the Enemy_BP. In order to do that go to the Event graph and add a New Event Called
Event BeginPlay then we need to add a DoOnce and Set Timer by Function Name.
In Set timer by function name set:
- Function name – SendTargetLocation.
- Time set to 0.05.
- Looping marked as yes.
This will make our enemy send target location every 0.05 second after game start. This is not a perfect implementation, but I want you to see that it’s possible. Later on, in next tutorial we will create a new method that will be called every time we need it.
 Send target location
Now that our Enemy_BP is finished, we can save and compile it and drag it to our game scene.
Adding Target Input Action
Before we add blueprint logic to our Player we will set out are special Target Input action.
To do that press Edit > Project Settings.. > Input > Bindings then add new Action Mappings call Target and add any Input you want to it in our case we use key “T” that key will trigger our target system.
 Bind an Input
Now we can go and open our player blueprint.
Add Target logic to player blueprint
Open player blueprint in this case it’s called “ThirdPersonCharacter” inside it, add new input event call Target and add logins as on picture below:
Make sure that TargetLockON using interface Game_BPI.
 InputAction Target
Now double click on Timeline_0 and set length to 0.2, auto start to yes and lopping to yes.
At this stage of our tutorial we can finally press play and test if our TargetVisual will appear above the enemy’s head after pressing our InputAction Target button.
If it works we can move to the final part of this tutorial.
Camera Target Movement Logic
We almost there now we have to go back to player blueprint to finish our Target logic.
In Cast To Zone_GI and drag a wire form “As Zone_GI” to GET a transform Position.
 Get a transform Position
Moving on a copy logic bellow to make camera move when enemy is targeted.
(here more information about logic)
You’ve made it to the end of Part 1 CONGRATULATION !
Now go and test your targeting system.
In part 2 we will add:
- Multi enemy that follow player.
- Target closest enemy to the player.
- Target only Alive enemy.
Thank you very much!