How do I find the nearest actor of a class to a certain location?

Hi, I’m trying to create a respawn system, but I want to respawn at the nearest spawn point to where the player died. How would I be able to use the array to find the closest actor in the defined class to the ‘Location on Death’ variable, to plug into the ‘Spawn Transform Location’? Here’s what I’ve got so far, thanks in advance!

I’m pretty sure you have to loop through all the player starts measuring the distance and take the nearest one.

Why have a random int in there?

Like this:

At the end of the loop ‘best index’ will be the closes player start.

The random integer was what they used in a tutorial I followed to get this far, haha, I just had it there so I was still able to respawn while I tested other things.

I’ve done what you’ve done in the picture, but my respawn mechanic is a function which I can’t create custom events in so I’ve done it as another function, but it doesn’t work, should being a function instead of an event make much difference? I’ve used the print string node on the ‘Best Index’ variable, but it just returns as 0 every time and spawns me at the same spawn point.

Respawn == Event -> functional code.

Ah, works perfectly, thank you so much! :smiley: