Im trying to find an easy way to search for the nearest actor to the player.
I thought this would work but it make the editor crash and I want to know why.
The idea is to pick an array of actors and compare their positions with the objetive actor, build a map (key: float distance, value: actor), ask for the smallest value of the distances array and then pick that actor as a value of the map. Im calling this in the begin overlap event.
The problem is this makes the engine crash, any idea why, and how to make this easy way?
Hello, I have a question. Do you have the log file or know what crash exception you are getting? It’s possible we could see if something is happening with the loop or a null exception and go from there.
If the keymap is giving issues, then you could simply just get the current object in the array’s distance, save it and it’s current location to a local variable in that function if the distance value is lower (Let’s name them ClosestActor and ClosestDistance). Once the for loop is done, you then return those variable’s values. For the first case we can just check if out array index is 0 to set the ClosestDistance.
I have an example of what that may look like as well.