Animators and dirtying UI

Hello,

after reading this best-practice guide:

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:

5298906--532131--setup.gif

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

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

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

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?


(all profiling was on an android device but I guess it doesn’t really matter)

Thanks a lot for any insight,
seb

4 Likes

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.

1 Like

Good to know I’m not alone :slight_smile: Hopefully somebody from unity will chip in sometime…

1 Like

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.

1 Like

+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 :slight_smile:

I hope so!

Waiting for an answer too! It would be so helpful to know…

1 Like

It’s important for me to know the answer too

1 Like

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

1 Like

up

Up

1 Like

up

1 Like

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.

1 Like

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.

1 Like

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!

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.

4 Likes

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.