Changing target after first actor is destroyed

I’m trying to make a tower defence game but the problem is that if I build a tower and 2 actors come in the same overlapping range of the tower the tower will shoot the first enemy but the second enemy will be ignored. I’m checking which enemy is entering via begin and endoverlap. Does anyone have an idea how to fix this?

A view while playing the game

When its done shooting the first target have it do a GetAllOverlappingActors, if you want it to prioritize at that point its kinda going to be up to you. You could do distance from tower to target, or if you have some kind of variable on the targets for how close they are to the end goal you could have it pick its target based on that. If you get all overlapping actors and there are no actors to attack then just have it sit there until one triggers the OnBeginOverlap again.

I tried doing what you said but its still inst working. This starts in the tick and if the Current Target inst valid(So no enemy is being targeted) it should check everything that is overlapping and set the first in his index as his new target. I’m not thinking about which it should select as enemy as long as it isnt checking any enemies at all :stuck_out_tongue:

I’ll set up some BP logic for you to try out, give me a moment.

Updated picture. Try something like this out and let me know how it goes.

It works perfectly! Thanks alot!!

Good to hear, don’t forget to mark this as a solution. :smiley:

Now as an optimization instead of doing this all based on BaseEnemy, you can set up the collider on the enemies to have a tag of Enemy. Then pull off the pin from Other Comp instead of Other Actor, check for tag Enemy and save the Other Actor ref as the current target. As well, instead of get all overlapping actors, you can get all overlapping components and check for the tag as well. Its best to avoid casting where you can, and this way the target doesn’t even need to be a base enemy. Also I wouldn’t normally put that stuff on event tick, instead I would do it on a timer by event for how ever often his attack speed or reload speed is. Also realized some of my logic wasn’t 100% so here is an update.

Seriously thank you for taking your time to show people how to do this efficiently.