Search Unity

AnimatorControllerOverride: ApplyOverrides WAY too expensive!

Discussion in 'Animation' started by LightStriker, Mar 19, 2018.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    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?
     
  2. Goatogrammetry

    Goatogrammetry

    Joined:
    Apr 27, 2017
    Posts:
    197
    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.
     
  3. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    hi, which version of unity are you using?

    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!
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    2017.3.1

    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.


    What makes Internal_SetClip so damn expensive??
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    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
     
  6. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    so it already fixed in 2017.3.1p3 and also in 2017.4.0f1
     
    theANMATOR2b and LightStriker like this.
  7. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    @Mecanim-Dev

    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 :eek:

    We also tried to use AnimatorControllerOverride[AnimationClip] directly but the result was nearly the same:


    Does there is a regression about this? Could it be fixed? We are dependent on this for our new dynamic system and it's a serious issue for us :(

    Thanks!
     
    Last edited: Jun 23, 2021
    Vincent454 likes this.
  8. FabulaLeonis

    FabulaLeonis

    Joined:
    Apr 11, 2015
    Posts:
    11
    @Mecanim-Dev definitely interested too in an update about that. Same issue with 2020.3 (and seen in a few versions prior to that, 2019 and such)
     
  9. Jack_Potter

    Jack_Potter

    Unity Technologies

    Joined:
    Jun 10, 2021
    Posts:
    5
    Hello @KospY, please can you let us know how many animations are in your controller and how many bones are in your rig?

    Thanks!
     
    KospY likes this.
  10. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    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.
     
  11. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    Hey guys I just sent a repro project for this (case 1353998).
    On the example It show 40 ms spike for 10 npc, just by changing ONE clip.
    upload_2021-7-28_22-52-16.png
    Hopefully it's a regression and will be fixed quickly.
     
    Last edited: Jul 28, 2021
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    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.
     
  13. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    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".
     
  14. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
  15. Vincent454

    Vincent454

    Joined:
    Oct 26, 2014
    Posts:
    167
    Thank you so much for finding and reporting this, they fixed it apparently! :)
     
  16. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    Yeah that's great! I'm updating right now to test and see if it work good now :)
     
    Vincent454 likes this.
  17. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    This is still an active issue btw, we have it with 2021.3 LTS
     
  18. KospY

    KospY

    Joined:
    May 12, 2014
    Posts:
    153
    TJHeuvel-net likes this.
  19. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
  20. TJHeuvel-net

    TJHeuvel-net

    Joined:
    Jul 31, 2012
    Posts:
    838
    Before:

    After:


    So yes its better, but still an issue.