Animator options - How to render hundreds of animations efficiently

So, I’ve spent the last few weeks reading up on animations and what alternatives I have to the Animator component since it’s performance is awful. So far I have not found an alternative that would fit my scenario.

I am making an RTS and will have hundreds of units animating on screen. Using Animator and skinned meshes is not an option due to the horrible performance. So my option are:

  • Use legacy Animation system. While this might improve performance, it’s not enough. Also using a legacy anything just feels weird.
  • Use a crowd-animation asset or make my own compute shader that creates textures for each animation and then can be used as a simple mesh, allowing batching. This is great for performance, a bit scrit-heavy but thats fine. My issue with this option is that it will not use IKs since it takes in the animation data without any post-processing like IKs, and if you use animations from Mixamo or assets, youll have issues like feet-shuffle that can only be solved with foot-IKs.
  • Using ReadPixels (Unity - Scripting API: Texture2D.ReadPixels) to render the animations into image files like .png and then use them as sprites. This is an option that would let me take advantage of foot-IKs. However I cannot find any information on how to begin an approach here, and this is where I could use some help. Is there any resource out there that does this or shows how it is done?
  • Use another tool like Blender, Maya or Houdini first. Workflow could be: find anim to use > import to Maya > Add foot IKs to remove feet shuffle > Bake animation > import to unity where it now works without IKs. Is this possible? Im not familiar with these other tools.

Other than that, just any solution that will let me play hundreds of animations without losing foot-IKs is what I need, so any information surrounding that is appriciated. Any form of animation baking that happens in playmode is what I am after.

Really? Are you sure you just aren’t asking it to skin too many verts per character or have too many bones or too much bone blending?

Just prima facie that would seem like an infinitely more likely problem than the animator being the cause.

Whatever is causing your slowdown, you have to find that out first.

DO NOT OPTIMIZE CODE JUST BECAUSE… If you don’t have a problem, DO NOT OPTIMIZE!

If you DO have a problem, always start by using the profiler:

Window → Analysis → Profiler

Failure to use the profiler means you’re just guessing, making a mess of your code for no good reason.

https://discussions.unity.com/t/841163/2

Notes on optimizing UnityEngine.UI setups:

https://discussions.unity.com/t/846847/2

Hi, I have profiled this quite carefully, thats how I got my nice list of options above :slight_smile: The Animator IS a problem. And I can promise you its not because of model complexity, they are as low poly as you get without looking like minecraft.

I always prioritize ease of use and readability > performance, but there are cases where its just not possible.

To be honest I have not run tests using legacy animation system but the thought of using something stamped legacy feels very wrong to me, and if its not, why the heck is it marked as legacy?

The Animator IS heavy, skinned meshes do NOT batch, this will cause an issue once you reach a few hundred units running around.

1 Like

Building an RTS in game object world is… well, let’s call it adventurous. You will have to write your own animation system.
The good news is, there are many examples out there. For ECS. Like Joachim’s from a couple years ago:
https://github.com/joeante/Unity.GPUAnimation or there are a couple more (even more recent) in the DOTS Topic.

Obviously you will need to adapt it/them for your own needs since they were written ECS and DOTS in mind. The short story is: you need to bake the animations into textures and then with shaders you can animate your instanced models.

The game will have a limit of 300 units. I am writing my AI using jobs/burst and everything runs great excepts animations, so Im not too worried about the gameobject part, I am not brave enough to tackle DOTS :slight_smile: thanks for the information!

Pathfinding used to be a huge issue but after writing my own it went from using 50% of frame time to 2-3%! burst is amazing

2 Likes