# Spawn actor in TargetPoint near the player

**URL:** <https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774>\
**Category:** Blueprint\
**Tags:** target-point, random, spawn-actor, unreal-engine, UE4, Blueprint, question\
**Created:** [January 21, 2019, 9:09pm UTC](https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774 "2019-01-21T21:09:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4544fdd6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4544fdd6](https://forums.unrealengine.com/u/anonymous_user_4544fdd6)\
**Post date:** [January 21, 2019, 9:09pm UTC](https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774/1 "2019-01-21T21:09:36Z")

</div>

Hello!  
I’m doing a zombie game and i spawn the zombies randomly between different target points, but i would like to ONLY spawn them in target points that are near the player. Is there any way to do it?

Thank you.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_776011b61](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_776011b61](https://forums.unrealengine.com/u/anonymous_user_776011b61)\
**Post date:** [January 22, 2019, 1:07am UTC](https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774/2 "2019-01-22T01:07:18Z")

</div>

HI

You could do a vector length check and if too far away, run the spawn again.

Or you could spawn them in random places within trigger boxes around the character.

Regards

---

<div class="post-metadata">

**Author:** ![Nebula\_Games\_Inc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Nebula\_Games\_Inc](https://forums.unrealengine.com/u/Nebula_Games_Inc)\
**Post date:** [January 22, 2019, 3:30am UTC](https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774/3 "2019-01-22T03:30:05Z")

</div>

I would store all your spawn points in an array. Then when you want to spawn a zombie have a function that loops through your array and checks each point against whatever set distance you want from the player. If it is smaller than the distance add it to a temporary spawn point array within this function (local variable). Once the loop is complete, have it select a random index from the temp array of desired spawn points. Then have a return node return this value from the function. After you can feed that location into a spawning function or spawn from within the previous function if you so choose.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4544fdd6](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4544fdd6](https://forums.unrealengine.com/u/anonymous_user_4544fdd6)\
**Post date:** [January 22, 2019, 8:56am UTC](https://forums.unrealengine.com/t/spawn-actor-in-targetpoint-near-the-player/441774/4 "2019-01-22T08:56:55Z")

</div>

Thank you! I’m going to do it with trigger boxes because i have walls and i dont want the zombie to spawn in a different room, but i found your answer very useful.
