Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Schedule animations performantly

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

  1. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,251
    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,533
    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,605
    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:
    140
    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:
    140
    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:
    140
    I couldn't find a way to avoid the
    Update.DirectorUpdate
    part when pausing/resuming... if you found any alternative solution, please share it!