2D SpaceShooter: Creation of mutiple different enemies

Hello guys,

I am facing an issue that I am not sure how to solve efficiently at the moment.

Let’s say that I have an idea of a Space Shooter game where I would like to create a lot of enemies that can be used along all the levels. I was thinking on using prefabs, but I am not sure if it is the best way since these enemies will be more powerfull in level 10 than in 1 for example… which means that their health will be higher (or any other stats). I guess I do not have to create one prefab per enemy variant, but I am not able to find any other way…

I am aware of inheritance and composition, but I do not see how any of these can help me to avoid the generation of +100 prefabs.

Would you be so kind to give me any advice I can follow to achieve what I am looking for? Thank you very much in advance!

P.S: Sorry for my English in case I said something wrong.

Any idea guys? :frowning:

Any suggestion, please?

Have you looked into Prefab Variants?

Hello runevision,

First of all, thank you for your reply.

Yes I did. My question is more on confirming if the only way to generate a big variaty of enemies is creating then “manually” from the editor. Is it the only way or is there any other possibility?

You can also create Prefabs (whether Prefab Variants or not) from scripting. I’m unsure what it is you want. You’ll need to keep track of what the stats are for each of your 100+ enemies somewhere. What would your ideal way to store this information be?

Or if you don’t want 100+ explicit variations, but just some logic that e.g. modifies the health according to what level you’re in according to some formula, then you can have the spawner script (assuming you’re using one) know what the current level is and modify the health of enemies that it spawns, right after they are spawned. There’s lots of ways to go about it; it really depends on what you want.

Hi again runevision,

Let’s say that I have one enemy (prefab) that has the following stats:

Firerate
Bulletspeed
MovementSpeed
Health

Imagine now that in one of the levels I am creating, I would like to add one variant of this enemy with all stats to 1 for example, another enemy with all to 2, to 3…and so on. So I have in the same level, the same enemy but with different stats. Then in another different level, I would like to also increase the stats in a new variant to make the game harder even using another variant of the same enemy. As per my understanding this can be done with prefab variants, but to me it looks like creating prefab variants one by one is a huge manual job…you are mentioning scrpting in your answer, would it be possible to use it shomehow in this case?

Thank you very much for your help :slight_smile:

Why? Creating a Prefab Variant is a few clicks. Sure, you will have to do it once for each variation you want, but that would be the case no matter what solution you choose. I’m not sure how you imagine to have hundreds of variations that you need to specify one way or another yourself without it being a huge manual job?

Yes it would, like I said. I can’t go in more specifics, it depends on your game and needs. You’ll need to learn the basics of scripting and how to apply it to take this approach.

Hello runevision,

Ok understood. I think it was a misunderstanding from my side regarding the “scripting” word. By scripting you mean the scriptable objects right? If this is the case, everything is clear to me and the post can be closed. If you do not mean scriptable objects, would you be so kind to tell me what do you exactly mean by scripting?

Thanks a million for your replies :slight_smile:

By scripting I mean anything you do with code. You probably already have code that instantiates the Prefabs (or else you will probably need it at some point). You can modify this code to set the properties on the instantiated Prefabs as you wish, getting the input for what those values should be from wherever you wish if you know how to code it. The details will depend on what exactly it is you want to do. I think you need to think about where you want to store the information about which Prefab variations should have which values.

Hi runevision,

Understood! Everything clear now. Thank you once again for your help. I really appreciate it :wink: