Ideal way to optimize enemy spawn points

Hello all,

I have an enemy spawn script that uses an enum, I can select what enemy I want it to spawn in the drop down editor and it instantiates the prefab. The problem I’m starting to have is, there are several variables on the script that transfer over to the instantiated object such as patrol or stand in place, react to noises etc. Now I’m getting into variables that need to transfer to the enemy that are enemy specific and the amount of variables not necessary for all enemy types are cluttering up the editor a bit. I was wondering how to go about maybe having the editor only show specific variables based on what enum setting I have selected in the editor. Or if there is just a better way structure-wise I should be doing this.

I prefer a spawn system because I’m saving whether these spawns are active to a file each time the player transitions to a new scene so it’s easier to grab from a universal spawn script. I know I could use interfaces instead but I also like the idea that nothing is instantiated at all on an inactive spawn for performance reasons. Even just a general point in the right direction would help. I don’t mind doing the research if I can just get an idea of what I should be looking for.

If you want different fields to show up based on the enum you’ve selected, you can code that using a custom editor for your component.

But if it were me, I would probably split this up. Instead of creating fields in the spawner that need to be copied into the enemy, have a “prototype” enemy that the spawner gains a reference to and then refers to it when it’s time to actually spawn something. This prototype could be a prefab, or maybe a scriptable object. You can use inheritance to make multiple kinds of “enemy prototypes” that have different fields on them.

2 Likes

Thank you!