Best way to set up similar animations for different enemies

Hello!

I’m working on a game where there will be a horde of enemies. It’s a 2D game with multiple sprite sheets. Most of them are slight variations, such as one zombie wearing a different outfit than another, skeletons with bows, others with swords, etc. There are approximately 20 enemies in total.

Among these 20 enemies, 15 of them share similar behaviors: all have a Walk and Death animation, while the other 5 are special enemies with additional Attack1 and Attack2 animations.

I would like to know what the best way is to organize and structure this in my game.

What I’ve tried

So far, I’ve tested two approaches, but neither seems to be the best solution. The first was creating a prefab called “EnemyBase.” It has a Status ScriptableObject and a default movement script that is the same for all enemies. In this prefab, I added an AnimatorController with the following state flow: Entry > Walk > (condition) Death. I created two empty Animation Clips for Walk and Death that have nothing in them.

Variants

I started by trying to create a Prefab Variant of the base Enemy called “ZombieSlow.” I added the new ScriptableObject to it, created the Walk and Death Animation Clips. But how do I assign these animations? I tried using the OverrideController. The first Prefab Variant works fine. However, when I copy and paste this Variant, the next Prefab Variant, “ZombieFast,” when I try to assign the Walk and Death animations, it references the Walk and Death animations from “ZombieSlow” instead… maybe it’s because they have the same name? When I try give it other name insted “Walk”, like “Walk1”, the OverrideController messup everthing, creating new fields, its weird.

Instead of using the OverrideController, if I just create a new AnimatorController, it works fine, but that seems like a lot of rework, right?

Prefab Copy

Instead of using Prefab Variants, I simply cloned the EnemyBase prefab. The problems are still the same. If I use the OverrideController, the animations with the same name start getting mixed up (even if they are in different folders). The best solution is always to create a new AnimatorController and redo everything in it.

What am I doing wrong?

Also, what is the best way to set up this monster horde? Should I create copies of the prefab or should I really use Prefab Variants? For my game, would one or the other make a significant difference?

I upload a video showing my problem: https://youtu.be/f0xTUsTGNDE

1 Like

Hi,
Good question. Good to come with a proper structure for your game.
I would choose to seperate the responsibility of the behavior. So make the behavior independent of the type of enemy and just configure which enemy has which behavior.

Make a seperate behavior classses and either add two scripts to the prefab (one for the type of enemy and one for the behavior), or make it an enum property and on constructing the Enemey class, make the right child-instance of the behavior.

Hope it helps. Else, try ChatGPT to come with a solution.

2 Likes