0
\$\begingroup\$

I read in a Unity blog post that using normal animation with UI in Unity is not really recommended, but instead you should use tweening if you can. To test this so I tried the same animation with both methods. I'm not really expert in tweening but this was really simple animation so I thought it should be ok. Basically I'm filling a image from 0 to 1 with looping animation. When I compared these two methods of animation in the profiler I noticed that while tweening, I get spikes of about 20ms for the time the tween is active, which is similar to normal animation. I'm not sure if this is normal behavior for UI or I am doing something wrong. This is my tween code:

Tween tween;
private void OnEnable()
{
    tween = image.DOFillAmount(1, 1f).From(0).SetAutoKill(false);
    tween.OnComplete(() => tween.Restart());
}


private void OnDisable()
{
    tween.OnComplete(null);
    tween.SetAutoKill(true);
}

I also tried something like this which does the same thing:

 private void OnEnable()
{
    tween = image.DOFillAmount(1, 1f).From(0).SetLoops(-1, LoopType.Restart);
}


private void OnDisable()
{
    tween.Kill();
}

Profiler Screenshot: enter image description here enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ Can you show us the profiler spike you're concerned about? \$\endgroup\$
    – DMGregory
    Commented Oct 12, 2021 at 13:12
  • \$\begingroup\$ I edited the question most of the spikes are under editor loop. \$\endgroup\$
    – Ivan
    Commented Oct 12, 2021 at 13:18
  • 1
    \$\begingroup\$ Sounds like it would be worth profiling a standalone build then, to see if these are just normal editor overhead and not a problem in your game. \$\endgroup\$
    – DMGregory
    Commented Oct 12, 2021 at 13:18
  • \$\begingroup\$ I will try that but the spikes only appear when i start the animation. \$\endgroup\$
    – Ivan
    Commented Oct 12, 2021 at 13:26
  • \$\begingroup\$ @DMGregory I tested it in standalone and the spikes are gone, still don't understand why do the only appear when I start the animation but if is not affecting the game performance it that is good for me. At least i know to check the profiler data in builds more often now. Thank you! \$\endgroup\$
    – Ivan
    Commented Oct 12, 2021 at 13:37

1 Answer 1

0
\$\begingroup\$

As pointed out in the comments the issue was normal editor overhead. While profiling game in standalone spikes disappeared.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .