I'm looking for an efficient way to create and use simple sprite animations in Unity.
My situation is the following: I have lots of entities (thousands) which need to be animated. These entities have the same (identical) animation running, which involves just sprite swapping. The animation loops endlessly. The following gif represents an example of what I need. In this example, a single animated object is placed on each tile.
Because of the number of objects, I would prefer to not have an animator-animation combo on each, and I would prefer not to have a MonoBehaviour on each. The overhead from both of these solutions will be way more than the game could handle. The required effect requires just a looping sprite-swapping animation, which can simultaneously run on thousands of objects. The gif above was made with animator-animation combos on each object.
The features offered by Unity's Animator component are great, however way beyond what I need here and thus the overhead is not worth it.
Optimisations I am aware of:
- Disabling animators when zoomed out.
- Disabling animators on objects which are out of view.
- Merging multiple objects into a single one which spans multiple tiles (does not apply due to nature of game)
- Writing my own sprite swapping animation component (not inherited from MonoBehaviour, similar in idea to this code), placing it on each item. Then creating an AnimationController object (inherited from MonoBehaviour), which updates all instances of my sprite swapping component at regular intervals. This is the solution I will likely go for if nothing else comes up, however involves hand-crafting animations, delays between sprites and such, which will be time consuming.
I feel as though others have surely come across this problem before, so I'm wondering how you solved it. Please also let me know if using Unity's built-in animator-animation system is in fact less resource intensive in this situation than I think.