How to keep tracking which of an array of objects is nearest to the player?

I’m having a bit of trouble. I want to find the “blockade spawn” nearest to the player every tick and and then move towards which ever one is closest to the player. It works well, but it doesn’t update. The AI will move towards the “blockade spawn” nearest to the player, but as soon as the player moves away and near a different one, the AI will still move towards the old one. I feel like i’m missing something small, but I can’t quite figure it out.

http://puu.sh/kkfnR/d2b03216e2.png

The AI To Move node gets called on each of your compare float operations which isn’t intended I think as it might cause the character to go to the wrong node before the correct target is set. So I would drag from the foreach completed pin to the AI To move node so it will only activate the node when it has checked all the potential targets.

A second thing it could be though this is just a guess but maybe the current closest value is always lower than the input distances when comparing in later runs, preventing you from having the intended target. At the end of your tick node tree try resetting the float to a higher number that all possible inputs would be lower than.

I tried both things, but they both resulted in the same behavior as before, nothing changed.

Can you think of anything else?

http://puu.sh/kkLUV/7b4abe72d1.jpg

I seem to have found the issue. The player controller is not physically tied to the character im using, it seems to start wherever the player’s character is spawned, but it does not stay with the character

I fixed this by instead getting the actual character that the player is using and then feeding that into the target actor for part of the “Get Distance” node

http://puu.sh/kl3VJ/645d5500a4.jpg

How would I go about tying the player controller to the character?

Linking player controllers to character:

If you have a character blueprint there is an input property to set the player input that the actor should be taking input from. (This is relevant to player input, might be what you need)

There is also a pawn property where you set what player controller should automatically control the pawn and things relevant to the AI control. (This is the one you want I think)

http://puu.sh/klo9s/5e08ca577c.png

Is this what you’re talking about? I changed those things but nothing happened. HOWEVER, I read up that PlayerController is just an interface, and might be why it doesn’t update in physical space. So instead I changed the whole thing to get the player controller and THEN get the controlled pawn, and it works all good now.

http://puu.sh/klofC/6ff8919bf1.png