Help around Enemies - Tower Defense

Godot Version

4.2.2

Question

I am trying to make a Tower Defense game and since I am quite new to programming I hit a small wall. It’s concerning the Enemies in the game.
Since it’s a tower defense game I want to have multiple types of enemies with different abilities ( different speed, different armor, spawn mobs on kill…)
I have been looking around online for some ideas on how to implement this and there were some interesting topics. With my current knowledge I understood the functioning of two ways I could implement this.

The first one is to create different scenes for every enemy and then instantiate it through the spawner somehow, which I think would add more lines of code but it would be more natural like that. I looked around online and saw a few projects that only had one enemy script. Is there a way that I haven’t thought off to use one script for all of the enemies but for them to spawn with different attributes and sprites? My biggest issue with this would be that I would have to spawn them through a spawner so the inspector wouldn’t be of much help except for resources maybe?

And the second approach to make it more modular that I found on the forum is Custom Resources and arrays that You can edit through the editor. Now I tried it out with the second one to try and learn how they function and managed to get the arrays working at least but the issue was with spawning. I made a basic Enemy Script and created 2 enemy resources but I didn’t know how to spawn those without placing them myself. The question I have is how do you spawn a enemy scene through Instantiate and when it’s spawned to get the properties of the resource. Also I read that if I spawn the same enemy type resource they share the values.

My question is mostly of the type in which way should I tackle the Enemies in the game. What would be the most beneficial way to introduce the Enemies in the game without more lines of code that would make it slower in turn.

You’re covering a lot of ground, so I’m just going to address the core. Create a different scene for each enemy type (not for each enemy instance), and instantiate them through a spawning process.

1 Like

I know, I truly want to challenge myself a bit and learn more as I go through with everything. Managed to do a great Tower Placement with a preview by doing just that and now this was the next bit of more important functionality.
Thank you for the thoughts, I was also thinking to try to go with that route as well since that’s the most familiar thing for me at the moment.
I created 3 different enemy scenes and I will either try to make a single Enemy script and see how I go with that or make for every enemy scene an enemy script with their different attributes. Gotta experiment to learn.

Creating a all-encompassing Enemy script is going to come back and bite you later.

Create an Enemy base class that contains all the data and characteristics that ALL enemies have in common, and then create your enemy subclasses that modify or extend the characteristics of the base Enemy class.

It’s more work up-front, but that work will pay dividends as your game grows.