# Best method for finding actors within a distance from player?

**URL:** <https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746>\
**Category:** Blueprint\
**Tags:** unreal-engine, question, Blueprint\
**Created:** [November 10, 2023, 5:32pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746 "2023-11-10T17:32:17Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![HappyKat100](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HappyKat100](https://forums.unrealengine.com/u/HappyKat100)\
**Post date:** [November 10, 2023, 5:32pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/1 "2023-11-10T17:32:17Z")

</div>

Hi,

I’ve got a bunch of items and they have sphere Triggers on them. When the player overlaps with the sphere the item highlights. However, I’m thinking having a lot of items in a scene running sphere triggers is probably not optimal. So, looking for some advice on the most optimal way to do it?

Some alternative options I can think of…

1. Have the sphere trigger on the player, not the items, so it’s only one object checking for the overlaps not many of them.

2. Have the player run a sphere overlap a few times a second (I don’t need it ticking every frame).

I here that the most performant option is often to get the squared distance from the objects, but I’m not sure how I’d do that without an overlap sphere to identify them first??

Any advice?

Many thanks!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 10, 2023, 5:35pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/2 "2023-11-10T17:35:29Z")

</div>

> [@HappyKat100](#):
>
> Have the sphere trigger on the player, not the items, so it’s only one object checking for the overlaps not many of them.

Seems like you’ve answered your own questions. Look into collision channels so the overlap only bothers with what it needs to rather than everything.

---

<div class="post-metadata">

**Author:** ![HappyKat100](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HappyKat100](https://forums.unrealengine.com/u/HappyKat100)\
**Post date:** [November 10, 2023, 5:39pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/3 "2023-11-10T17:39:10Z")

</div>

Thanks, yeah I’m thinking it’s one of the two options.

Although now I think about it, overlap triggers get a single actor, not an array of all actors so I think my option #2 is likely better.

So, I’m thinking the best method here might be to run an overlap sphere maybe 3 times a second and collect all actors that it collides with (as they will have a specific collision setting to filter them).

Also, I assume sphere triggers run every frame?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 10, 2023, 5:43pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/4 "2023-11-10T17:43:41Z")

</div>

How do you want it to work? Actors highlight (or do what they need to do) when you:

- get close them, automatically
- press a button

All still with proximity in mind, ofc.

* * *

How close is this:

> [@Third person crosshair object highlight troubles](https://forums.unrealengine.com/t/third-person-crosshair-object-highlight-troubles/252041/7):
>
> Do tell how it goes. This can be set up with very little ticking, actually. You could even line trace just a couple of times per second, and the player wouldn’t notice. But this particular ticking is something I wouldn’t worry about. @ConvenientBox How close is this to what you’re trying to accomplish?

---

<div class="post-metadata">

**Author:** ![Ligazetom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ligazetom](https://forums.unrealengine.com/u/Ligazetom)\
**Post date:** [November 10, 2023, 5:51pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/5 "2023-11-10T17:51:12Z")

</div>

It seems you are pre-optimizing. You can be sure that attaching functions to events such as `OnOverlapBegin` and `OnOverlapEnd` (something along those lines), will be the most performant option there is.

Your fear of getting only one object per event is wrong as your callback will get called per every object overlapped. So if you want to keep an array of objects within the given distance then all you need is to push on `Begin` and remove on `End`.

Avoid ticks, avoid timers. These are not things you want to be inconsistent.

Performance wise you can make custom channel reserved just for this.

---

<div class="post-metadata">

**Author:** ![HappyKat100](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HappyKat100](https://forums.unrealengine.com/u/HappyKat100)\
**Post date:** [November 10, 2023, 5:51pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/6 "2023-11-10T17:51:45Z")

</div>

Yeah, they just highlight and I add them to an array. Don’t need the closest or anything, just all within a distance of the player so I can highlight them.

Here’s what I’m currently thinking (from the player BP)…

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/2/d02daa8e27376cea4e6602fad59c2d63c81e5083.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 10, 2023, 5:54pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/7 "2023-11-10T17:54:28Z")

</div>

Have a sphere overlap on the player instead and:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/d/33dfbff6f784eba13516028d13f7b20d9d098def.png)

Now it runs only when you actually overlap (again, collision channel) and you have an array of actors close to the player. Would that work?

> so I can highlight them.

You do not even need an array then. Send the message to the actor on Begin / End overlap and tell it to act accordingly.

In the same thread, a couple of posts below, there is a [step-by-step](https://forums.unrealengine.com/t/third-person-crosshair-object-highlight-troubles/252041/13) that does the above, and more.

---

<div class="post-metadata">

**Author:** ![HappyKat100](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HappyKat100](https://forums.unrealengine.com/u/HappyKat100)\
**Post date:** [November 10, 2023, 7:04pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/8 "2023-11-10T19:04:28Z")

</div>

Super helpful, I’ll try that, thanks very much!!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [December 10, 2023, 7:04pm UTC](https://forums.unrealengine.com/t/best-method-for-finding-actors-within-a-distance-from-player/1378746/9 "2023-12-10T19:04:46Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
