Dotween: OnComplete not fired when time is 0 inside the sequence

Created on 27 Mar 2018  Â·  9Comments  Â·  Source: Demigiant/dotween

var sequence = DOTween.Sequence();
sequence.Append(Hand.transform.DOMove(startPos, 0).OnComplete(() =>
{
print("foo");
}}));

this prints nothing. However if the time is changed to 0.01f, then the callback is fired.

resolved

Most helpful comment

Ahoy!

Hey, thanks for the nice words :)

I'm working on a BIG new feature for DOTween (I'm making it all modular, so you'll be able to disable the physics/audio/UI parts if you want, since Unity 2018 allows that), and I'm currently tearing my hair apart because it's really complex (but I'm managing :P). As soon as I finish this I'll get back on the OnComplete issue (I wanted to do that since a while, but I can't touch the code for other things while I do the modular feature). But since my brain will probably be completely fried by this modular feat, may I ask you to bump this issue on Tuesday (when I hope I'll be done)?

Cheers :)

All 9 comments

Same problem discovered here as well.

in this particular case ,theoretically since the time is 0, you don't actually need an OnComplete. you could just add the print("foo") line straight afterwards

```C#

// this is going to run immediately
var sequence = DOTween.Sequence();
sequence.Append
(
Hand.transform.DOMove(startPos, 0);
)

// so no need for a callback
print("foo");

HOWEVER.. 

if you paused the sequence and then ran it later, so you do actually want a callback when the tween completes, then I agree this would be a problem.

`OnComplete` needs to fire in all cases

Worth pointing out the `OnComplete` is on the tween, not the sequence. 

In the example below only "bar" and "baz" are printed

```C#
sequence.Append(bottle.transform.DOMove(pos1, 0).OnComplete(() => { print("foo"); }));
sequence.Append(bottle.transform.DOMove(pos2, 0.1f).OnComplete(() => { print("bar"); }));
sequence.OnComplete(() => print("baz"));

@wilczarzgit @Nomy1
as a workaround you can use OnStart() for zero-time tweens (but not OnStepComplete) to effectively achieve the same thing.. since time is 0 then start and end are theoretically the same thing.

C# sequence.Append(bottle.transform.DOMove(startPos, 0).OnStart(() => { print("foo"); })); sequence.Append(bottle.transform.DOMove(endPos, 0.1f).OnComplete(() => { print("bar"); })); sequence.OnComplete(() => print("baz"));

That is completely beside the point. Time of the tween can be a variable
and the callbacks should always be fired, regardless of the time. I am
surprised I need to explain this..

W dniu pon., 4.06.2018 o 05:52 Jozef Pierlejewski notifications@github.com
napisał(a):

as a workaround you can use OnStart() for zero-time tweens (but not
OnStepComplete) to effectively achieve the same thing.. since time is 0
then start and end are theoretically the same thing.

sequence.Append(bottle.transform.DOMove(startPos, 0).OnStart(() => { print("foo"); }));sequence.Append(bottle.transform.DOMove(endPos, 0.1f).OnComplete(() => { print("bar"); }));sequence.OnComplete(() => print("baz"));

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/Demigiant/dotween/issues/194#issuecomment-394227602,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGbEhITfKn_LmGY5zLkOMuhwyQc3flfKks5t5K7ugaJpZM4S8n_9
.

>

Pozdrawiam,
Tomasz Wilczyński

Ahoy,

If I may, DOTween is an animation engine, so 0 time tweens shouldn't really exist :P That said, I did work on it and implement a way to make 0-duration tweens callbacks work, but that's as long as the callbacks are on the main tween, not inside a nested one. So if you move your OnComplete and chain it to the Sequence it should work.

P.S. I do have in my todo list a "make nested 0 duration callbacks work" card, but it has very low priority because I believe it's out of scope (and not easy to do, I already tried), so I don't know when I'll get to it

@Demigiant

as per my example, (internally) can you not make the event that triggers OnStart also trigger OnComplete if time = 0?

you are right they probably shouldn't exist for non-animation, but as you can probably guess I use it to do lazy value setting ;)

eg

DOFade(0, 0)

instead of

C# SpriteRenderer rend = GetComponent<SpriteRenderer>(); Color col = rend.material.color; col.a = 0; rend.material.color = col;

etc

that said I'm mostly only doing that before a Tween to 1, so it is part of the animation in some respect.

@Demigiant I'd like to echo the sentiment in this thread and say that for us, having OnComplete be correctly fired for zero-length tweens would be very helpful. We often parametrize our tweens, and sometimes when we want it to be instant we have to always remember to set the time to 0.01f instead of just 0f which "should work" from a designer's point of view.

Our workaround has been to add boilerplate code before the tween that bypasses DOTween entirely, and instead sets the values (that would be tweened) directly and fire the callback (that would be OnComplete) right away, but it seems like it would be straightforward for DOTween to do this internally and save us the trouble!

This comment aside, I don't get the chance to say this often: thanks for the great work, I am a big fan of DOTween and I use it in all my projects :)

Ahoy!

Hey, thanks for the nice words :)

I'm working on a BIG new feature for DOTween (I'm making it all modular, so you'll be able to disable the physics/audio/UI parts if you want, since Unity 2018 allows that), and I'm currently tearing my hair apart because it's really complex (but I'm managing :P). As soon as I finish this I'll get back on the OnComplete issue (I wanted to do that since a while, but I can't touch the code for other things while I do the modular feature). But since my brain will probably be completely fried by this modular feat, may I ask you to bump this issue on Tuesday (when I hope I'll be done)?

Cheers :)

Ahoy again.

This has been fixed. Check this thread ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShadowTM picture ShadowTM  Â·  4Comments

ceyhuntasci picture ceyhuntasci  Â·  5Comments

eduardbosch picture eduardbosch  Â·  3Comments

dooprod picture dooprod  Â·  11Comments

SharpEdgeMarshall picture SharpEdgeMarshall  Â·  3Comments