Performance: UI animations
MEDIUM IMPACT
UI animations affect the smoothness of interactions and the responsiveness of the interface during user input.
IEnumerator AnimateUI() {
while(true) {
uiElement.transform.position = new Vector3(Mathf.Sin(Time.time) * 100, 0, 0);
yield return null; // Wait for next frame
}
}
// Start animation coroutine once
StartCoroutine(AnimateUI());void Update() {
// Animating UI position every frame with heavy calculations
uiElement.transform.position = new Vector3(Mathf.Sin(Time.time) * 100, 0, 0);
// Heavy logic inside Update causing frame drops
PerformComplexCalculations();
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Heavy calculations in Update() | High (every frame) | Multiple per frame | High (complex redraws) | [X] Bad |
| Coroutine-based animation with simple transform changes | Low (only transform) | None or minimal | Low (GPU compositing) | [OK] Good |