Demigiant / dotween

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

Append Callback Between two Appends issue #575

Open R0tmayer opened 2 years ago

R0tmayer commented 2 years ago

Hi there!

I want to change variable value after first Append is done and before second Append is started

Here is my code

        sign = 0;

        DOTween.Sequence()
            .Append(transform.DORotate(new Vector3(0, yAngle, 0), duration))
            .AppendCallback(() =>
            {
                var sign = Random.value > 0.5f ? -1 : 1;
            })
            .Append(transform.DOLocalRotate(new Vector3(0, randomAngle * sign, 0), randomDuration)
                .SetRelative(true));

But the problem is that when the second Append starts, the value of sign = 0, but the sign should be 1 or -1

JLDooley commented 2 years ago

I'm running into something similar. The callback is working as intended but the new values are not being implemented. My best guess so far is that the tweening targets are being cached when the sequence starts, and aren't updated if the variables change.

    `Sequence rockSequence = DOTween.Sequence().SetLoops(totalCycles)

    rockSequence
                .Append(transform.DOLocalRotate(nextAng, time).SetEase(Ease.OutQuad))
                .AppendCallback(() => multiplier = rockSequence.CompletedLoops() == totalCycles - 2 ? -1.75f : -2f)
                .AppendCallback(() => nextAng += multiplier * offset)
                .Append(transform.DOLocalRotate(nextAng, 2 * time).SetEase(Ease.InOutQuad));`
fakegood commented 1 year ago

my workaround to this issue was creating a getter for that variable, it will then get the value again when it is called.