Cycling Through Enemies

So I have a lock on system set in place, and I’d like to cycle through the enemies (in no specific order/structure) that are in front of me, basically turning the one on the side to locked on and the one I was locked to to locked off, with what I have set in place I can do that, the problem is that it only does that once, and when I click the key to cycle it doesn’t do anything afterwards.

Basically I just want to get all enemies of the class, cycle through them to check if they are alive, and basically setting the one after as locked on, and keep doing that forever (cycling through them).

How can I achieve this with what I have? Thanks in advance.

Your current setup is going to very quickly loop through all of Test Enemy actors in your level and set the Lock Target to each one of them sequentially, overwriting the previous one. The last one in the array will always end up being set as the Lock Target. I think something like this will do what you need:

Thank you very much, it works as I wanted it to work! There’s only one minor issue, I have two enemies placed in front of me, when I target the one on the right, it all goes smoothly (switches right away to the other), but when I target the one on the left first, it doesn’t switch the first time I hit “3”, only the second, afterwards it all goes well, any idea what might be provoking this?

Here’s how they are displayed in front of me (I’m locked to the left guy) if that matters:

Here’s a vídeo demonstrating the issue:

It seems to be an ordering issue to me.

It’s because the enemy you have targeted initially happens to be the first one in the array. You need to check if the enemy at the current iteration is the same as the Lock Target. If it is, enter the Do N node again to skip it.

Do I check that after the exit of the Do N? And to get the enemy at the current iteration, do I set a variable from the GET node (the one coming from the Get All Actors of Class)?

You would compare the output of the CastTo node with the Lock Target. If they are the same (equal), then loop back into the Do N node, otherwise set the Lock Target as you normally would. This means you would have a Branch between the CastTo and the set Lock Target.

Yeah, that seems to fix most of the issue, thank you a ton for your help!