Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Schedule animations performantly

Discussion in 'Animation' started by DevDunk, Jan 21, 2024.

  1. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,136
    I want to make a system to schedule animators every other frame, to save performance. Just like seen (a bit too much) in games like Pokemon Scarlet.
    I can call Animator.Update(deltaTime), which does reduce the amount of frames animations take up, but this will not use any multithreading/jobbified or anything. When running all animators at regular framerates this approach is a lot slower than Unity figuring out the animation.

    Is there a way to accomplish this within Unity? Or does it have to be supported more on the engine side?
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,520
    I did an experiment whether I could tick my animators less frequently when zoomed out and came to the same conclusion. I could however sort animation states by high detail / low detail, e.g. idling was pretty unnoticeable to stop animating unless in focus. Some things could be manually animated instead of with animators. These aren't great workarounds.
     
  3. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,582
    There's an example in my Animancer plugin which uses the equivalent of animator.Update and someone suggested that they were seeing better performance by instead unpausing the character for a frame and setting its speed such that the delta time of that frame advances it by the desired amount during Unity's regular animation update so it can benefit from the multithreading stuff. In my brief test I wasn't able to get any significant improvement in the frame rate, but it's worth a more thorough investigation and the same concept might work for regular Animator Controllers too.

    It would definitely be nice if they added the ability to batch evaluate a bunch of Animators as a job though.
     
    Lo-renzo and Yuchen_Chang like this.
  4. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    129
    Here's my Implementation to do frame-dropping, both for performance and for anime-look effect: AnimatorDropFrame.cs (-> Github ReadMe)
    Explained in the Readme file in Github, but simply I was just checking if the animator should update this frame, and pause/resume it.
    By pausing/resuming instead of
    Animator.Update()
    , the animator still uses it's multi-threaded thing, so it should be efficient.

    If there's many animator, you may want to seperate to several frames to avoid spike.
     
    rc82 and DevDunk like this.
  5. XiaHong1

    XiaHong1

    Joined:
    Mar 31, 2022
    Posts:
    2
    By pausing/resuming instead of Animator.Update(), It will increase Update.DirectorUpdate() .
    upload_2024-4-28_15-36-47.png
     
    Yuchen_Chang likes this.
  6. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    129
    Haven't notice that pitfall. Thanks for sharing! Looks like it's not good to pause/resume frequently then, will gonna do some research on it.
     
  7. Yuchen_Chang

    Yuchen_Chang

    Joined:
    Apr 24, 2020
    Posts:
    129
    I couldn't find a way to avoid the
    Update.DirectorUpdate
    part when pausing/resuming... if you found any alternative solution, please share it!