# How to get random spawner and only spawn if in range?

**URL:** <https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945>\
**Category:** Blueprint\
**Tags:** spawn, random, range, unreal-engine, question\
**Created:** [April 14, 2021, 10:01pm UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945 "2021-04-14T22:01:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![fuzileiro34\_PT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fuzileiro34\_PT](https://forums.unrealengine.com/u/fuzileiro34_PT)\
**Post date:** [April 14, 2021, 10:01pm UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/1 "2021-04-14T22:01:45Z")

</div>

Hi, i’m new, and this is my first project. I have some spawners in the level (one in each corner for example), and i want to only when the player gets near the spawner, only that spawner spawn the enemie. I made this but it don’t work well

 ![335928-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/a/16ad20284151c9fbbafc59ea6e27452deb4f8dec.png)

 ![335929-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/c/c/2cc62f384928ac20cdfbe950886b7db3c7d20d0d.png)

 ![335930-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/7/e97a230805b53452dbce0fadaa1add6707da43cb.png)

With what i have now, the enemies only spawn if i´m in range a spawner, but they spawn in the others spawners to. If someone can help i appreciate, 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:** [April 15, 2021, 7:07am UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/2 "2021-04-15T07:07:17Z")

</div>

Each object should be responsible for its own thing. If you have a spawner, make it spawn things. Avoid relaying on the Level Blueprint as much as you can, no matter how tempting it is. It’s a death trap worse than a spider spawner. :o

* * *

Consider the following approach:

## Spawner actor:

 ![335948-screenshot-1.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/4/f/d4fef6f4ae91abe10dc166fe4c4a0f3ca08db793.jpeg)

- I have a bunch of these in the level

 ![335949-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/1/2/4127c4485fcc73e71f5f869bc632b2f640f770f4.png)

- each spawner can do this:

 ![335961-graph.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/2/5/d25c07db318badbe8acaa00a7d6c0c2b0d722335.png)

To visualise:

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/7/9/279f7cba3ee840e4cbcc0582eab30a97e0dbd636.gif)](https://gyazo.com/40ff0ca6f673a66e4b791df50675eda6)

Do tell if that helps.

---

<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:** [April 15, 2021, 7:22am UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/3 "2021-04-15T07:22:25Z")

</div>

Regarding me insulting the Level Blueprint - I exaggerate, it sure has its uses. You can use it as a manager if this level has some unique functionality.

If I wanted to choose a random spawner and have it create a monster regardless of the player being close by:

- a new _Custom Event_ in the Spawner blueprint hooked up to the same nodes as its timer

 ![335962-customevent.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/6/d/b6dafb103f8ed3878e049097786bb7769fa20b37.png)

- get the Spawner references:

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/a/5/ca5a81be8e2bed9646e59777a670245c3070c260.gif)](https://gyazo.com/6f89b14178ca5f8244324c8dc137b08f)

- this makes the array of Spawner actors, starts a Timer and makes it pick one spawner at random
- we then call the custom event mentioned above

 ![335963-lb.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/5/6a51d7e334a557c43b1eecbb0dfc566760d44760.png)

- now the spawners work even if the player is away
- and if we step into the spawner sphere, both timer will run - the one in the spawner _and_ the one in the level blueprint

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/9/73947a58ca2ff434ef29c4760438ef96439d3d43.gif)](https://gyazo.com/8d44bb6806afef9a1d6ca1dae1331cba)

Hope this helps.

---

<div class="post-metadata">

**Author:** ![fuzileiro34\_PT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fuzileiro34\_PT](https://forums.unrealengine.com/u/fuzileiro34_PT)\
**Post date:** [April 15, 2021, 4:18pm UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/4 "2021-04-15T16:18:37Z")

</div>

Thank you very much, is working really nice now. I will adapt the other things to this new spawner, i don’t think there will be problems. Once again, thank you very much!

---

<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:** [April 15, 2021, 4:44pm UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/5 "2021-04-15T16:44:34Z")

</div>

And if you working with timers, these can come in handy:

 ![336004-screenshot-3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/a/2/1a26b05b7104ec36a05c59b5d14916c1fad53d9e.png)

You can pause Times and see how long they’ve been running for. So the Level Blueprint can easily create time-based waves of enemies, for example.

Good luck with the rest!

---

<div class="post-metadata">

**Author:** ![fuzileiro34\_PT](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fuzileiro34\_PT](https://forums.unrealengine.com/u/fuzileiro34_PT)\
**Post date:** [April 15, 2021, 4:46pm UTC](https://forums.unrealengine.com/t/how-to-get-random-spawner-and-only-spawn-if-in-range/481945/6 "2021-04-15T16:46:39Z")

</div>

Ok, thanks for the tip
