Hi all, I am a newbie to Unity,
would like to know how is this situation normally handled in Unity:
The scenario:
My game (2D) has got 50 types of enemies with some generic behaviors and animation states:
- standing : animation state idle
- walking : animation state walk
- attack : animation state attack … and so on
[My old method]
I was previously making game on GM:S. I normally do it like following:
Firstly create sprite for each states for all enemies respectively, and named them accordingly while importing to asset library.
For instance:
- spr_enemy1_idle,
- spr_enemy1_walk,
- spr_enemy1_attack,
- spr_enemy2_idle,
- spr_enemy2_walk,
- spr_enemy2_attack…and so on.
Then i will have a parent object for generic enemy behavior,
that will store the ‘enemy name’ and ‘state name’.
When i tell certain enemy instance on stage to perform an action, it will look for the ‘enemy name’ and ‘state name’, then look through the asset library and bring up the animation sprite (animation state) accordingly.
for example:
when instance of enemy1 were to perform an attack action, the script will look for asset with name “spr_”+“enemy1”+“_”+“attack”, get the sprite, and set the current sprite_index (or animation state in unity) accordingly.
in short, i import all my sprites, name them accordingly, and script the generic rules how the animation state works. Then when i create an enemy instance on scene, i just need to define the enemy name (eg. “enemy1”, “enemy2”) for it to work accordingly. If i need to further customize certain behavior, i can create a cub-class from there.
*note: The look up on the asset name can be done once when the instance initiated and stored in a reference variable, so that it won’t be looking through the asset library every time when the animation state changed.
[in Unity]
From what i have learned so far. User normally create animator controller(for each enemy) and animation states (for each states of respective enemies) then link them in animator controller accordingly.
When i was following the 2D Roguelike tutorial, it uses ‘Animator Override Controller’ to define animation state for Enemy2 which have similar behavior as Enemy1. Which is quite handy, but still, when i have 50 or more enemies, i still have to manually create another 49 ‘Animator Override Controller’ then drag in corresponding animation states in to the component to override the states. I think this is rather repetitive and hard to manage. If i later decided i need to add a new state (eg: “jump”), i will have to go through the process 49 times again…
How is such situation normally handled in Unity?
Thank you ![]()

