# How can i get the closest actor to the player

**URL:** <https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999>\
**Category:** World Creation\
**Tags:** actors, actor-blueprint, distance, unreal-engine, question\
**Created:** [March 9, 2021, 6:30pm UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999 "2021-03-09T18:30:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fahood00451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fahood00451](https://forums.unrealengine.com/u/Fahood00451)\
**Post date:** [March 9, 2021, 6:30pm UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999/1 "2021-03-09T18:30:39Z")

</div>

how can i get the closest actor to the player from an array of actors  
(closest crystal to player from 100 crystals)

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 9, 2021, 7:13pm UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999/2 "2021-03-09T19:13:44Z")

</div>

Basically do a get all actors of class ( get the world location ) and measure the distance between them with distance ( vector ).

But how often are you doing that? It’s not a cheap operation.

It would be better for each crystal to know it’s distance from the player.

What are you trying to achieve?

---

<div class="post-metadata">

**Author:** ![Fahood00451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fahood00451](https://forums.unrealengine.com/u/Fahood00451)\
**Post date:** [March 9, 2021, 8:12pm UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999/3 "2021-03-09T20:12:38Z")

</div>

a compass that shows you the crystal nearest to you

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [March 9, 2021, 8:20pm UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999/4 "2021-03-09T20:20:44Z")

</div>

You could change it to a sphere trace for crystals, that only crop up on the radar when they are within a certain distance… Then it really is a kind of radar 🙂

---

<div class="post-metadata">

**Author:** ![Fahood00451](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fahood00451](https://forums.unrealengine.com/u/Fahood00451)\
**Post date:** [March 10, 2021, 2:21am UTC](https://forums.unrealengine.com/t/how-can-i-get-the-closest-actor-to-the-player/479999/5 "2021-03-10T02:21:44Z")

</div>

now thats something that i shouldve rthought of  
thanks!
