top of page

Does using Animator in Unity UI cause performance issues?

  • Oct 21, 2024
  • 2 min read

Updated: Oct 28, 2024

Welcome to the first post on the Urz Games blog!


A while back, especially from 2019 onwards, there were several discussions about using Animator for UI animations, especially on mobile devices. What happened is that many developers noticed a notable amount of rendering calls in their game's profiler, related to CanvasRenderer, and consequently a loss of performance.


It didn't take long for them to discover that the culprit was Animator. Because of the way this system worked, Animator marked the Canvas as 'dirty' which forced its components to update, even if nothing was actually happening. This generated unnecessary CPU processing and a large amount of Garbage Collector.


The solution found was to use the Tweening technique, a way to make a transition between two states or values. Many tools have emerged, such as the well-known DOTween, which are lightweight and have a good flow for changing properties such as position, scale and colors, in other words, everything you need to make HUD animations.


But then, Unity brought in update 2019.3, more specifically in 2019.3.0f5, a major update that aimed to be the beginning of the correction of this Animation-HUD interaction problem. In the update notes, there is the following text:


Release note unity 2019

We see that they fixed one of the main issues in this update.


This was followed by other improvements in the latest versions of Unity, including optimizations to the UI system, improvements to the Animator and recalculation managemen


Having said all that, the question remains: will using Animator on the HUD harm my project? And the most direct answer is no, depending on the version of your project.


But another question has arisen among many developer forums: is it worth using Animator in the HUD?


Now, if UI animations, in general, are so simple, often involving only scale, position and at most colors, why use a complex animation engine like Animator for this?


This is a very valid discussion, since if you have ever used a Tweening tool, you probably, like many developers, really liked how customizable and simple it is to use. In addition, it allows for more precise control of values, since the values ​​are controlled by script, a feature that even makes Tweening fit better into your project architecture.


But does that make Animator worse? Not at all. But it's worth remembering that Animator's function is to work on complex animations, and when you decide to use it in the HUD, keep in mind that you'll be using a whole system to perform actions and calculations that are generally simple.


So, to conclude this topic, when to use one or the other? The answer is, it depends:


  • If your UI requires complex, sequential animations, Animator is still a viable choice, especially with Unity's optimizations. It offers flexibility and detailed control over state transitions.

  • For simple animation like moving, scaling, or changing the color of a button, Tweening is more efficient and easier to implement.

  • If you are using a version prior to 2019, DO NOT USE ANIMATOR.


Did you like the content?

Consider following our page, we will soon bring you more topics like this.


 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
©2024 Urz – All Rights Reserved
bottom of page