Jump to content
  • Advertisement
G-Dot

Unreal Which way is the best to spawn enemies

Recommended Posts

Hello everyone! I was working on my spawn algorithm for enemies and come up with the question. Wchich way is the best to actually spawn them in Unreal Engine 4? I want to describe my situation. In my game there are a lot of moments when enemies spawn constantly, for example there are always more then five enemies (aka AI Actors) on the level. To keep them always on map I got an algorithm but I don't know how I should do it properly. There are two ways that I found out:

  1. Just a normal lifecycle: enemy spawns, he dies from player and actor and controller get destroyed.
  2. A little bit tricky. I spawn a good amount of enemies at the begging of level at one hided place (for example 20 enemies under the map). Thaen I spawn some amount of them and after death instead of being destroyed Actor returns to his initial place and wait till his next spawn.

I don't know which way is better from technical point that's why I can't decide which one to use. But my algorithm can handle both of them.

Share this post


Link to post
Share on other sites
Advertisement

I like going with one, because then you wouldn't have unused resources (the enemies sitting around under the map), and spawn new enemies when needed.

That is unless there is a reason to not kill and move the actors.

Share this post


Link to post
Share on other sites
Posted (edited)

Your second example is an object pool. If there are lots of the same enemy in the level that die and "spawn" frequently, this is an optimal choice. In cases where any object gets spawned and destroyed frequently, such as bullets of a weapon, an object pool is certainly a valid choice.

EDIT: If you haven't yet, check out Reset(). It will simplify the respawning functionality.

Edited by conditi0n

Share this post


Link to post
Share on other sites
9 hours ago, conditi0n said:

Your second example is an object pool. If there are lots of the same enemy in the level that die and "spawn" frequently, this is an optimal choice. In cases where any object gets spawned and destroyed frequently, such as bullets of a weapon, an object pool is certainly a valid choice.

Yeah, I think this is my choice, because gameplay is kind of divide into two parts: one of them is an action, where enemies spawn each 40-50 seconds. But I got 7 types of enemy in my games and some of them (weak ones) spawn really frequent and in big amounts, but more strong enemies spawn with slower rate. Also I didn't understand a  trick with bullets. Where are I should stole them if they don't use. And yeah, I got different types of bullets for each weapon in my game, but they all inherit from main class.

Share this post


Link to post
Share on other sites
Posted (edited)

40-50 interval seconds is almost never, think around 500 / second or more as "frequently".

Edited by Alberth

Share this post


Link to post
Share on other sites

 

2 hours ago, Alberth said:

40-50 interval seconds is almost never, think around 500 / second or more as "frequently".

 

But In this 40-50 seconds interval I will spawn not one single enemy but f good amount of them. And I think it's impossible from gameplay point if view to spawn 500 enenmies per second.

Share this post


Link to post
Share on other sites

Yes, my main point was mostly that what you see as "often" may not be so often from a computer point of view, running at a few GHz.

Before considering more complicated schemes like pre-construction or object pooling, I'd first try the simplest approach. If that works, you're done. If it doesn't work, measure where your performance problem is, and fix it.

In about 9999 of the 10000 times, our guess of where a problem is, is just dead wrong. Avoid wasting time on solving problems that don't even exist.

 

Share this post


Link to post
Share on other sites
4 hours ago, Alberth said:

Yes, my main point was mostly that what you see as "often" may not be so often from a computer point of view, running at a few GHz.

Before considering more complicated schemes like pre-construction or object pooling, I'd first try the simplest approach. If that works, you're done. If it doesn't work, measure where your performance problem is, and fix it.

In about 9999 of the 10000 times, our guess of where a problem is, is just dead wrong. Avoid wasting time on solving problems that don't even exist.

 

Yeah, I got you point. It's very wisdom advice and I should give a try to my new algorithm. Rigth now I spawn enemies without any pool and every time they die it means that their objects get destroyed. But it's very stupid and straigth forward: i just spawn predetermint groups of enemies. My new algorithm tries to normalize spawn amount by max enemy count and max enenmy weigth. But it's not fully integrated and I hope it will work better then current one.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!