Spawning multiple enemy types

Hello,

I am looking for a straight-forward way to generate multiple instances of an enemy (in my case, three kinds of bunnies - white, black and brown).

If I understand correctly, I cannot change atlas used within the sprite component of a game object on runtime. Do I have to create one game object and one associated factory per enemy type or is there a better way (that doesn’t involve lumping all frames of animation for all enemies into one atlas)?

If you for reasons cannot bundle all images in one atlas (which is always preferrable if you can as you will possibly lower the amount of drawcalls ) you can either:

  1. Do what you proposed and create a new gameobject, new factory etc. This is not so fun if you have the same logic in the scripts etc and just want to adjust properties in the script for different behaviour

  2. Create several sprites (with different atlases) within a gameobject and disable/enable them as you are passing in a “type” go.property into the factory.

2 Likes

Because the atlas becomes to large or because you will never have all enemies active on a level at the same time? If it’s not one of these reasons then I’d suggest that you reconsider and put all animations in a single atlas since that will be way more efficient to render

Mainly because of concerns about the size of the atlas. Right now the atlas for each enemy is 2048x1024 in size. The number of animations is quite large.

Ah, I see. Well, then you’re unfortunately not able to simply change the animation on the sprite. I guess the options provided by Andreas are the ones to look into. Or maybe switch to spine animations instead of flip book if that helps.

I will be going with the second option provided by Andreas. We have tried integrating Spine into our workflow and found out it is pretty tricky to animate characters in isometric perspective.