Help with identifying the actor closest to the pawn within a subset of actors

Hi all. I’m looking to create a function called every frame that identifies the distance between the player pawn and ten (or so) other actors, and then returns the name of the actor to which the distance is the shortest (i.e. closest to the pawn). I cannot think of a way to do this - I understand you cannot dynamically update data tables in UE, so it would not be a case of parsing a data table. I have thus far tried to use structs to set variables consisting of the actor name and a float value for distance (yielded through use of the Distance (Vector) function), but I can’t think of how to compare these variables so that I may know which actor is the closest. All help is much appreciated.

Hi @Sellswood369

If you can make an array of these actors is pretty simple,
Just get this array and get the location of everybody and make a list of distances, another array of floats.
Then making a 3° array with int you sort them by what you want.
Here an example i posted some days ago, about sorting an array on speed.

Hope is clear enough

Untested but looks like it should do the trick:

Sorry for the delayed response, but thank you both so much for the above suggestions - I have tested both methods, but I think I shall use @Everynone’s version.

It could also be done without the array if *all *you want is 1 result; but you may sometimes want to get more out of it - let’s say you’d want the 3 closest / furthest objects instead - having the distances in an array would make it easy.

You read my mind @Everynone, I think in future it would be more useful to have the closest 3 or 4. I’ve never tried to get more than one min value from a float array though - is there an easier way to do it than removing the min float from the array and then getting the min float (2nd lowest) of the array once again?

Thanks again

Sadly, there’s no proper sorting in BPs. You can either do what you said or you can:

Annotation 2020-08-12 093433.jpg

LE Extended Standard Library - a marketplace plugin that shouldn’t be free but it is.

Awesome thanks for all your help