Targeting system

Hi guys, I recently created a targeting system for my player character, this system works fine but the issue is the enemy character that I’m targeting, I dragged in 4 of the enemy character, they use the same blueprint, now if I target just one out of the 4, any changes I make to that one, take for instance launching the enemy character, the 4 enemy characters will be launched, is there any way to make the changes affect only the character currently being targeted, I created an actor variable inorder to set it up as the current targeted character but it’s not much help, any suggestions?

Hi @ValLevi

Need a bit more info, are all of the enemies spawned from a blueprint? If so how do you store the targeted enemy? And how do you attack the enemy?

Might help to see the blueprints. Its actually very simple process u need so shouldnt be hard to fix.

In general target enemy(line trace) store the target actor in a Actor variable. Perform action on that actor variable.




How do I save the current targeted character as an actor, I tried doing that buh failed cause using the actor I can’t play anim montages or do some certain things with it, the enemies are dragged from the same blueprint

ok where ever that graph is on the left make a variable called say “ClosestAI”, and set the type to your “AI Enemies” type. Then once you have found your closest enemy set that variable to it.

then when you deal your damage target “ClosestAI” as it will only contain your closest one

The attack system works fine, what I did was getting my closest enemy, orienting my character to it and letting it take damage as I attack it, the enemy’s life reduced, like they all have individual healths but somehow when I launch that closest character, all the others play the anim montages but I want only the character I launched to play the montage, I dunno if it’s because they share the same blueprint, then another issue is when I save it as an actor, that’s the targeted actor you see on the screenshot, because I put my targeting system on tick, if at any point I launch a certain character and during that instance another enemy becomes my closest enemy, that new closest enemy gets launched instead, even tho it was the previous closest enemy I launched, so how do I store that current closest enemy so that regardless of the time I get a new closest enemy, whatever I do to it affects only it

if you target the individual closest ai they shouldnt all play montage
unless u targeting them all.

Using tick is gonna hurt you as its so fast its targeting them too quick if they get closer maybe?

ok lets rewind.

How do you want to detect the nearest character? Automatically or on a key/input?
Also do you want it to be the same character until its either dead? or you choose someone else?

Automatically

ok once selected you dont want it to change right? until u kill it ? or maybe have a key to retarget?

I want it to change based on which character is the closest at any given point, I intend to setup an AI to match the system

ok so whats happening is while you are running code to attack, you are retargeting
so all of them get hit most likely

so, to fix this create a boolean variable called “Attacking”
when you attack set it true, at end of attack set it false

then in your code for the detect closest, at the very beginning to a branch
if “Attacking” true then do nothing
if its false find nearest target

14.03.2023_17.42.49_REC
Look it’s targeting just one at any point in time but how do is save that one
I used a sphere collision to limit the space of those that can be targeted so it doesn’t get too heavy

When I’m attacking I attack the current closest enemy but if another one becomes the closest enemy my character ignores the previous one and focuses on the current closest enemy

i told you here how to store it

but it changes too quick based on your tick finding a new target if they all just as close so add in the attacking check so it dont attack them all

ok here is a better idea, do you want it to run the check “AFTER” the target u have has been attacked?

I don’t understand it, how do I go about it, if it’s possible, a blueprint reference would be appreciated :slightly_smiling_face:

What’s the check for?
Is it for storing?
If so, then yes, once the enemy is hit, it should store it

i need to understand the flow of the process to do that.

This is how i would do it.

check i have a target > if not find closest one > attack that target > after attack ends > repeat

Whoa, yeah I think this is okay, I have the rest setup, I just need to know how to check if I’m currently targeting an enemy

ok so create a new variable inside your player character blueprint

call it “AITarget” make it the same as your AI Enemy Blueprint

Make sure you select the blueprint type of YOUR enemies