How to make ai pick up the closest gun

i want my ai to pick up a gun that is the most closest, i already have allthe systems to pick it up and stuff, i just want to know, how do you get the closest actor from a class in a level?

Set an insanely high starting distance as the “found” nearest gun’s distance - then For Each Loop through the guns in the scene to check each - in turn - to see if it is closer than the one saved as “nearest.”

thank you!