Right now, when a player equips a weapon, we override the animation it can play.
Our animator is about 300 animation. Currently, doing ApplyOverrides cost about 140ms, 40 of which is in Animator.SetupControllerDataSet, and the rest in ApplyOverrides itself.
Is there a way to change animation in an OverrideController without killing the framerate?
wow! That sounds like a coding issue for the Unity guys. I agree that 140ms is pretty bad unless its actually loading those animations or something. Otherwise it seems like my old Atari ST would get similar results LOL.
we did fix a huge performance regression recently in ApplyOverrides, the system was wrongly sending a notify per clip rather than one for the batch, so if you changed 300 clips in a batch with ApplyOverrides it was sending 300 rebind to the animator … ouch!
So… pretty much the latest “non-beta” version.
Managed to improve it by doing a diff of the previous list of animationclip and only pushing what actually changed… but equipping a sword is still 45-50 animations, which means 27-28 ms! Considering we are doing a 60 FPS game, that way above our 16 ms budget.
since you are changing a clip we need to recompute the bindings for the controller, but rather than doing it only once for your batch of 50 clip, it does recompute the bindings after each set clip.
I will try to find out if this backport is landing soon in 2017.3
We are using Unity 2020.3.11 LTS and it seem that this issue still happen, we are only sending an array of two elements to ApplyOverrides and sendNotification is doing 26ms spike for 6 NPC
Our character have 68 bones, and our controller have around 212 animations (if I refer to the animator override controller). But we only send an array of 1 to 3 animations to change.
That’s a rather large number of animations. Presumably it has to gather the bindings from every animation so I wouldn’t be surprised if the performance cost was directly proportional to the number of clips.
You might want to look into the Playables API or other animation systems that let you avoid needing massive Animator Controllers.
If we look at the third post from Unity, it seem that sending a notify should happen per batch and not per clip.
And the first guy have an issue with a controller with 300 animations, and Unity fixed that for 2017.
Anyway going over 100 animations is easy for any serious project, would be surprised if it’s “by design”.