Demigiant / dotween

A Unity C# animation engine. HOTween v2
http://dotween.demigiant.com
Other
2.33k stars 350 forks source link

DOTweenPro - tmproAnimator Create Alot GC #530

Closed asad-ch closed 2 years ago

asad-ch commented 2 years ago

I'm Using Dotween to animate my TMP Text. When I build on android this creates a lot of GC. How Can I reduce GC so I can use this in my game. The text animates once in OnEnable and never changes again. And I don't enable and disable this in level. GCAllocation

private void OnEnable()
    {
        TMPtext.SetText("Find Somethig New In Unity ");

        DOTweenTMPAnimator tmproAnimator = new DOTweenTMPAnimator(text);

        for (int i = 0; i < tmproAnimator.textInfo.characterCount; ++i)
        {
            tmproAnimator.DORotateChar(i, Vector3.up * 90, 0);
            DOTween.Sequence()
                .Append(tmproAnimator.DORotateChar(i, Vector3.zero, 0.4f))
                .AppendInterval(1f)
                .Append(tmproAnimator.DOColorChar(i, new Color(1f, 1f, 0.8f), 0.2f).SetLoops(2, LoopType.Yoyo))
                .SetDelay(0.07f * i);
        }
   }
Demigiant commented 2 years ago

Ahoy!

The TMProAnimator creates some GC (but very minimal) on the creation of the tweens, and then has zero allocation per-frame. From your profiler it seems that you have some warnings happening and those are the main cause of GC (which is indeed a lot of GC and definitely not normal). Remember that you should check if a character is visible before animating it (see example here). Also be sure that you're using the latest version of DOTween (1.2.632) because the first release of the TMPAnimator created even more GC if used incorrectly, while the latest does some extra checks to prevent it.

As a secondary note, if you just need to rotate a character at startup, instead of creating a 0-duration tween before the sequenced ones I'd recommend to simply add a [From](http://dotween.demigiant.com/documentation.php?api=From(T ) to the DORotateChar animation you're appending (so that you create one less unnecessary tween): .Append(tmproAnimator.DORotateChar(i, Vector3.zero, 0.4f).From(Vector3.up * 90))

Closing this but feel free to reply if you have questions.

Cheers, Daniele