Is there a way to optimize animators?

Hi everyone,
I have a 2D scene that has literally hundreds of gameobjects, each with an animator. When I go to the profiler, Animators.Update is taking up pretty much all of my CPU cycles. Now, I’m curious if there is a better way to do this, and if anyone knows…

I have changed all of the animators to CullCompletely, so they are only active when on screen.
From what I have heard, using “Animations” rather than Animators is much more efficient, but I’ve also heard that you cannot use an “Animation” in 2d unless it goes into an animator.

Can anyone give me some guidance on where to go? Or is this a limitation of Unity?

Thanks!

i had the same issue with my game i have simply check if the animation game object is visibile to player

if visbile play animation or else disable animator compoenet.

This will have to be tested for your specific game, because it depends…

Have you attempted to reduce animation frames in any of your imported animations?
I don’t know if that would help reduce overall cycles, but doesn’t hurt to try.

Probably can reduce animated frames quite a bit, don’t need a 30 fps animated swaying environment object.

Also might consider a tweening solution for things that can be ‘tweened’ instead of animations. Will have to be tested to see what is more optimal.

The main way is to clamp values that are almost zero down to zero. This prevents multiple blends from being applied when it’s not even noticeable to the player.

After that, I would recommend making an AI / Management script that sits in your scene and iterates through the active objects. Based on their distance, zone, visibility, activity etc you could change how much of their behavior is active and determine whether their animations are on or off. Culling is good but if you have animation events, such as footsteps, then you would need to be creative with how you play footsteps that are on culled AI. This is why I prefer to make my own culling method because the Unity Cull is not always ideal.

Think about what makes your AI inactive || active and set up a logic check to see what level of detail it qualifies for. If an AI is far from the player, legacy animations will be faster but this means you need to make a script to deal with legacy and one to deal with animator animations. Just make your game modular and disable objects that are not needed.

The management scripts are not too heavy, just set a cooldown for X amount of time between each iteration.Everytime the cooldown reaches zero, have the management script iterate through the active/inactive AI and determine what each AI should be set to. If it’s heavy then you just increase the cooldown. Works well for me.