Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Animators and dirtying UI

Discussion in 'UGUI & TextMesh Pro' started by sschoellhammer_snowprint, Dec 19, 2019.

  1. sschoellhammer_snowprint

    sschoellhammer_snowprint

    Joined:
    Dec 18, 2018
    Posts:
    8
    Hello,

    after reading this best-practice guide:
    https://unity3d.com/how-to/unity-ui-optimization-tips

    Especially the bit:

    Optimal use of animators on UI elements
    Problem: Using animators on your UI

    Animators will dirty their elements every frame, even if the value in the animation does not change. Animators have no no-op checks


    I went ahead and replaced a whole bunch of buttons with simple tweens in our projects UI. Sadly I couldn't really see any real difference in performance, so I decided to setup a simpler scene to understand what is really causing dirtying in the UI.

    This is my test scene:

    There's about 500 images in one canvas, and buttons to toggle on and off 3 images with scripts that change image color, position and scale per frame and an then one image (red) that is using an animator to animate its position:

    setup.gif

    this is when ONLY the images that scale/move are enabled. As expected they trigger buildbatch while they're active:

    move_scale.jpg


    This is when showing only the image that is changing its color which also dirties the layout (and increases time in BuildBatch).
    Looking at Graphic.cs in the ugui code there is
    next to
    public virtual void SetLayoutDirty()


    also

    public virtual void SetVerticesDirty()

    so I actually don't quiet understand why any layout needs to be dirtied here? Oh well.

    chaning_image_color_layout_and_batch.jpg

    This is when just showing the image with the animator on it:
    I can only see an increase in ms. while the animation is actually playing, so it does not seem to dirty as the article implies. Has something changed there? Am I missing something?

    animator_affecting_rebuildBatch.jpg
    (all profiling was on an android device but I guess it doesn't really matter)

    Thanks a lot for any insight,
    seb
     
    Last edited: Dec 19, 2019
  2. SleepyAgapornis

    SleepyAgapornis

    Joined:
    Sep 7, 2018
    Posts:
    23
    I have the same question here... I was also reading about UI performance and animators and I've done some tests by separating objects into sub canvases and/or using tweens...there were no significant improvements in performance while using sub canvases... and tweens only improved my fps by a few numbers.. nothing significant to stop using the animator component... I was asking myself if this does have to do with this improvement of version 2019.3.0?
    UI: Fixed performance issues with Animation by not dirtying the Layout if an Animation updates items.


     
    MasterZuh likes this.
  3. sschoellhammer

    sschoellhammer

    Joined:
    Feb 15, 2013
    Posts:
    46
    Good to know I'm not alone :) Hopefully somebody from unity will chip in sometime..
     
    SleepyAgapornis likes this.
  4. mjbcfc

    mjbcfc

    Joined:
    Jun 7, 2017
    Posts:
    3
    Can anyone from Unity comment on this please? I've spent some time transitioning to a tweening system for all my UI elements however it seems using an Animator for UI elements is no longer bad practice with regards to dirtying and updating every frame regardless if anything actually changes in the UI. Would love to get this confirmed, thank you.
     
    MasterZuh likes this.
  5. MasterZuh

    MasterZuh

    Joined:
    Jun 1, 2020
    Posts:
    1
    +1 on the update, "UI: Fixed performance issues with Animation by not dirtying the Layout if an Animation updates items." Does this mean that we can use animators without having to worry about performance now? Someone from unity enlighten us pls :)
     
  6. Ian094

    Ian094

    Joined:
    Jun 20, 2013
    Posts:
    1,548
    I hope so!
     
  7. lleirbag

    lleirbag

    Joined:
    Aug 2, 2013
    Posts:
    1
    Waiting for an answer too! It would be so helpful to know...
     
    DanWeston likes this.
  8. Metall_East

    Metall_East

    Joined:
    Feb 6, 2019
    Posts:
    2
    It's important for me to know the answer too
     
    Last edited: Sep 3, 2020
    DanWeston likes this.
  9. DanWeston

    DanWeston

    Joined:
    Sep 9, 2014
    Posts:
    32
    Starting out on a blank project in 2020 I'm keen to know if this is also the case? Was going to make a test project and profile away to double check! It will be super handy to use animators more again, I was scared off them with many after the Unite 2017 talk
     
    chilledbits likes this.
  10. Dinojr

    Dinojr

    Joined:
    Mar 14, 2017
    Posts:
    1
  11. renchy91

    renchy91

    Joined:
    Nov 6, 2019
    Posts:
    2
    Up
     
    chilledbits likes this.
  12. Hummelvogel

    Hummelvogel

    Joined:
    Apr 4, 2018
    Posts:
    8
    up
     
    migs_jelly likes this.
  13. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    I sent a documentation bug report to Unity, case #1308776. I'll update once they respond.

    Also, OP never clarified which version of Unity they were using. From the UI in the screenshot it did not seem to be 2019.3 (that contains the mentioned fix) since that version started using flat UI elements. The last version that used the old shaded UI elements was 2019.2. It could mean that there had been fixes on UGUI and Animator interactions.

    Anyhow I am glad that I stumbled on this post. I was implementing UI animations and wanted to iterate quickly. I previously used tweening components and they suck so much at creating and iterating complex animations.
     
    Last edited: Jan 24, 2021
    wulcat likes this.
  14. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    I just did an experiment in 2021.1.0b3 and I can confirm that once the animator on the UI goes to an empty state i.e. no animation clip is playing and the UI becomes still, Canvas.BuildBatch call no longer occurs.
    Changing color properties still causes Canvas.BuildBatch call to occur which matches what OP was seeing.
     
  15. Moostauche

    Moostauche

    Joined:
    Oct 1, 2020
    Posts:
    1
    Apologies, quite new to this and I’m working on UI at the moment (dialogue system with animated character panels). Would you say that Animator is OK now!
     
  16. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    Not really. See the response I got from Unity staff (kudos to them BTW):

    This does gives some lead on where the performance is lost. I may do more experiment on this if I have time, but you can do the same. After a few tries I ended up not using Animator because I prefer scripting for consistent and reusable behavior (plus I suck at keying animations), so I now only use Animator as a WYSIWYG mockup and then implement the animation in code.
     
    Last edited: Feb 3, 2021
  17. pistoleta

    pistoleta

    Joined:
    Sep 14, 2017
    Posts:
    536
    I have a short question about this... I have a few buttons in UI and im using unity animations to create an effect whenever they are tapped...
    If I were to enable/disable the animations in hierarchy before and after the tap would they still be 'dirtying' the UI?
    Thanks in advance.