How to make my weapon attack the enemy nearest to it?

Try Ticking something like this in the pawn BP:

  • a sphere overlap fetches nearby actors
  • its radius is the max range of weapons you’ve got atm
  • we sort by local_distances, here a local variable in a pure function
  • I draw a debug sphere at the closest target

Not optimal but could be a start. Instead of Tick, you could run this on a Timer, let’s say 10x per second. This can be further optimised by dynamically adjusting the size of the sphere overlap. If there’s an enemy close by, there’s no need to check for valid targets at the edge of the screen. Some other bits and bobs can be improved.

Would that work for you?