How to inquiry the nearest actor?

theres probably a better way to go about it depending on your circumstance, such as overlap events or line traces which would be easy to implement and possibly more optimal.

but to give a brief overview of what you asked for. you would first need a get all actors with tag node, this should return an array which contains all actors that have the tag your looking for. you then need to parse this array to find out which actor is closest. to do this you need to use a foreachloop which gets the distance to (get distance to node) the player from the actor, then compares that distance to the distance of the other actors. the way i implement this is to have a variable which contains the closest actor then compare each other actors distance to the current closest, if the new actor is closer then you set it as the current closest and move on. once you find the closest you can then move on to the rest of what your looking to do by comparing the “distance to” to the max interact range. then you can do the last part though im not entire sure what you mean there but im assuming your trying to call an event in the actor.

8 Likes