x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Spawning random number of enemies at the same time on location

Hi there,

I'd like to know how to spawn a random number of enemies (Like between 1 to 4) at a spawner. I'm able to spawn enemy one by one, but can't figure out how to spawn multiple enemies at the same time.

I'm using this tutorial form UE Youtube Channel : https://www.youtube.com/watch?v=4SKY_wfHN1g

So, here are my Blueprints : Gamemode : https://i37.servimg.com/u/f37/11/08/58/06/gamemo10.png Spawner : https://i37.servimg.com/u/f37/11/08/58/06/spawne10.png

Thanks !

Product Version: UE 4.14
Tags:
more ▼

asked Jan 11 '17 at 09:06 PM in Blueprint Scripting

avatar image

Ednoc
10 1 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Since computers are not capable of doing more than one thing at a time, you are going to have to use some kind of trick to make it appear like they are all spawned at the same time. The spawning code is a bit slow (but not that slow), so if you absolutely need all of them to appear at exactly the same instant, I would spawn them hidden and then when they are done spawning, make them all visible at once.

I looked at your blueprints and I am a bit confused by the first one. Personally I think there is never a reason to use the Tick event. So I would move the code you have in the Tick even to the Begin Play event or whatever other event might be the trigger for the spawning to start. The Set Timer by Function Name looks good and is my preferred method to get around not using the Tick event.

The other thing that is confusing is that I see you are trying to spawn more than one enemy, but I don't see a For Loop. I think you want to add a For Loop to your SpawnEnemy that loops the number of times of enemies you want to spawn (pass in the number of enemies as a parameter to determine how many times to loop). I think if you add a For Loop to the SpawnEnemy they will stop spawning one at a time and you won't even need to start with them hidden.

more ▼

answered Jan 11 '17 at 10:34 PM

avatar image

Dartanlla
2.6k 62 27 281

avatar image jman2015 Feb 06 '19 at 09:16 PM

Upvote for suggesting to not use Tick. I only use it if it absolutely necessary. And when I do I do as little as possible there as that is a good place to start introducing performance problems by overusing Tick.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi, thank you for your answer !

https://i37.servimg.com/u/f37/11/08/58/06/itwork10.png

I followed your instructions and... It works pretty well !

Now, about the Tick Event, why do I use it ? Because if I use Event Begin Play, the event is going to be fired only one time and only one. Which means enemies are going to spawn at one spot only and it won't change through the game is runing.

If I use Event tick, every 2 seconds ( For example with my delay ), my enemy spawn is going to change every 2 seconds.

more ▼

answered Jan 12 '17 at 09:54 AM

avatar image

Ednoc
10 1 4 7

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question