Tower Defence - Spawning Creeps (Blueprint)

Hi guys,

I’m looking into building a basic tower defence game in blueprint. One hurdle that I am encountering is spawning creeps and targeting priority. My plan is to create an array of pawns that are spawned at runtime, which means I can use the index of the array to prioritize the targeting of the creeps (the lower the number, the higher the target priority).

That sounds good in theory, however it seems like you cannot populate pawn arrays before runtime. I would like to populate my array before runtime. Does anybody have any ideas? Is there a better way to approach this problem?

Ehm, may i ask you why you want to do this before runtime?

You could just spawn the creeps from class. I mean, making a spawn point and letting creeps run from point to point with a navmesh. You would let the level BP spawn your class (creeps).

You just need a method to time your waves. A for loop that loops 10 times and spawns a creep every loop with a delay node of 2 seconds or so. A branch that spawns different groups of creeps depending on the wavenumber (0-9).

You could use a second loop to go through a wave array that has different creep classes, like small, middle, big, flying in it to alter the creep waves. Ehm… you could also add the spawned creeps to an array inside your level BP when you spawn them and later let your turrets use this array to determine which creep they should attack. If they die, you let them remove themself from this array. You can use this array to let the tower loop through it, check the current health and attack the weakest target. Or check if it’s flying and near/in the line of sight with some enums/bools.

To have different creep waves i would use a class array with all the creep classes and a second array with the first “array” in it. So you have an array of an array of classes to go through each wave.

These are just some ideas. You can also have a look at the Tower Defense project of Epic Games in the Market Place.

Thanks for your answer, it sounds like i need a complex web of arrays! What you’re suggesting does negate the need to do it all before runtime.

I’ll have a play around with it and post my results.

It could be that the web of arrays is bad or there could be a better idea at all, but i normaly throw out my ideas and think about it with a mindmap later.

Maybe you could really have a look at the project from epic. It’s free and they used 2 different creeps. Maybe you can see how they did this.

Could be that a struct or something like this may also work.

Even though eXis answer is pretty great I want to go a bit further.

To dynamically spawn enemys you can not populate an array before runtime.

However it is not actually that hard. You can easily do a spawn volume and for each spawned enemy add the result from the “Spawn Actor from Class” into your array with the “ADD” node.

To not have any complications you have to create a “master enemy” bp meaning your basic enemy. HP, take damage and all that stuff every enemy should have and create your array with that type.

All enemy types should be a subclass of that class which allows you to have all enemys in one array.

For turrets I would highly recommend something different. Don’t check the position in an array but instead add a cylinder component (or use the existing one) and expand it to your radius size. That way you can check which enemys are currently overlapping with your tower and like this create an array for the tower to go through.

Then you can test for each minion the distance to the base (or the next checkpoint taking into consideration that one minion might be already one checkpoint ahead) and attack the one closes to the next checkpoint with the highest amounts of checkpoints passed within the range.

If you simply go after “When was it spawned” you end up in situations where slow tower completely break your system.

Also the target finding way I just described allows you easily to create different modes (closes enemy, enemy with most HP, enemy with shield, etc.).

For spawn orders I would actually suggest to use excel. The integration for unreal is not exposed to blueprint yet but if you have any way of coding just a very little bit it sure is worth it. Nothing will make it as easy to add waves and as easy to modify them as the excel solution.

Thanks for the additional infos. That’s what i meant with “thinking about i later” :smiley: It often turns out that my ideas are good for beginning but need fixing somewhere. Good idea with the cylinder!

The Spawn Volume though could also be done with the level BP it self or? If the Level BP spawns the Creeps, it can use the result to add it into the array itself, no need for a spawn volume, or? :smiley:

Technically no but it makes it a lot easier to work with spreadsheets for spawning and you can randomize the exact spawn location and most importantly:

You can use it in multiple levels. With a Level BP you would have to copy all nodes over and over.