Basic question for ai move to (and continuing to move afterwards)

I’m trying to have an enemy unit attack the closest target, then continue to move to the next closest target after the first one is destroyed, it moves to the first one just fine and destroys it but stops after that, also I’m getting the on fail ai move to print string as soon as I hit the play button, I’ve tried different blueprint setups, watching multiple videos/ looking and reading up on it and I just can’t seem to figure it out. Is anyone able to help explain what I have wrong here? I’m pretty new to this and would hopefully get things going and learn more, so if you could recommend or link anything to help on the learning aspect of this also that would be great. Also sorry if the pictures aren’t very good, it’s the best I can get atm.


Is the health of the first unit more than 5? Because I’m hard pressed to see how you get a second attack out with this BP. Also, you’re creating a new timer for each enemy in range. That’s gonna bog down your game.

From what I’m seeing, you only have your actor going to the enemy on overlap. But DURING the overlap, nothing will happen unless a new enemy comes into range.

This would require a lot of changes to get right. I like the part where you’re updating the “Detected” list. That part is good. The rest needs changing.

I’d create a variable for your timer.

We need to think about what you’re trying to do.

  1. We want the actor to chase enemies.
  2. We want to attack the enemy as long as possible.
  3. We want to stop chasing an enemy when it is out of range (this will work for both death and running away).

That’s it. That’s all that’s required.

So how do we chase enemies?

In the graph “On Component Begin Overlap”, we only want to start chasing if the “Detected” list is empty. If it’s not empty, we should already be chasing and we don’t need to redo the chase.

So after the add, if there is only ONE item, then do the rest of what you have. So you need a “Branch” node there. Also make sure to store the timer handle in a variable when you create it. After “Apply Damage” and “Print String” make both execution paths connect to the same node that checks if “Detected” is not empty with another “Branch” node. If it’s not empty, continue (loop back) to “AI Move To”.

Ok, so that will handle moving and attacking.

Next is stopping the moving.

So in the “On Component End Overlap”, after the REMOVE node, check if it’s empty. If it is, then call “Clear and Invalidate Timer by Handle” on your timer variable.

That should be a good start.

Oh, and “Move AI To” can fail if your actor is too close. So the “On Fail” pin should check if you’re close enough for an attack and if so, just Apply Damage.

Ok I’ll try out your advice here thank you. The damage part I just added to check if the unit would move again after destroyinf thaw first target, the target just has a simple event any damage-destroy actor, I do have an attack setup on another test bp that seems to be working fine atm, although I don’t think quite exactly what I’ll need, buts it’s something for now, I’ll post that because it did try working with the pawn sensing for the movement logic also but that route wasn’t working for me either.

Ah I’m a new user so I can’t post any pics again here.
I did get pawnsensing movement to work but ran into a similar problem with moving to the next target, I didn’t realize pawnsensing didn’t repeat and couldn’t find a workaround for it.

Actually, now that I think about it, you may have trouble with your Overlap events because I don’t think you’re allowed to execute the same graph multiple times at once and since “AI Move To” is delayed that may ignore further overlap events.

Oh there we go, I am able to upload another pic, this is the pawn sensing movement I was trying to get to work (some things are currently unconnected as I was trying different things before moving on to try the sphere overlap movement) for the most part this was also working moving to the closest target, but again I couldn’t find a way for them to move to the next closest target once one is destroyed

Also this is set to only target one thing atm, as you can probably see, but I think you probably get the idea here,

I’ve never used pawn sensing, but from the little I’ve seen, you’d need a way to reset pawn sensing so that it triggers again. I think you need to use a DoOnce node and when you’re no longer tracking a target, you reset the DoOnce node to allow more pawn sensing.

This might take me a minute but I’ll post my attack logic, looks like I can only post 1 pic at a time, I imagine there’s a way to add movement into it but I’m just not seeing it, the unit will target/track facing and attack its target and when that target is destroyed it will target the next unit, but I also don’t have the closest target working for it also, everything else seems to work though. Maybe this might help

Uploading: image.jpg…

Sorry, you said you got it working? I’m not sure I’m following what you’re trying to add now? You said it’s not tracking the closest one? I think that has to do with your sensing component with its sensing vision. It won’t be able to detect anything behind it unless you also use hearing. At least, I think that’s how it works.

Assuming two actors are within sight, then during the “On See Pawn” event, you need to check if that pawn is closer than the pawn you’re currently chasing. If so, set the current actor to the pawn to be chased and call “AI Move To” again (or ChasePalyer). You’ll have to check that the actor is not dead before calling “Chase Player” if that’s what you’re using.

edit: And set ChasingPlayer to false before calling ChasePlayer.

I’d add a check if the Pawn pin on “On See Pawn” is the same as TowerReference, don’t do anything. But if ChasingTower is true AND Pawn is closer, then set ChasingPlayer to false and continue as usual.

You likely also need something to notify you or check that when the tower is dead, that you reset your variables. So in “On See Pawn”, you probably want to check that if the Tower Reference is dead, then set ChasingTower to false so that you can chase a different tower.

I’ll try to post a BP. Give me a moment.

Something like this:

This is only for towers. I couldn’t follow your logic for target pawn. You’ll need to combine the two somehow.

“IsValidAndAlive” is a custom function that checks if the reference is valid and if the pawn is alive.

I stopped at “Chase Player” node. I couldn’t see the rest of your graph, but it would continue on.

Also, where “ChasingTower” is set to false, you may need to also reset your other variables to false like “Chasing Unit” and “Attacking”.

Forgot to check if the Pawn pin is equal to the TowerReference. If so, don’t do anything. It should still work as is, but just safer to compare the pawns to avoid unnecessary work. You can add a branch node right at the start.