Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOTween cancellation token not immediate #378

Closed
Atlinx opened this issue Jul 18, 2022 · 8 comments
Closed

DOTween cancellation token not immediate #378

Atlinx opened this issue Jul 18, 2022 · 8 comments
Labels

Comments

@Atlinx
Copy link

Atlinx commented Jul 18, 2022

I've noticed that whenever I wanted to cancel a tween immediately, I'd have to wait until the end of the frame for the tween to stop. Is it possible to kill the tween immediately, so my cancel logic can become synchronous instead of asynchronous?

Ex. (What I'm doing right now)

cancelTween?.Cancel();
cancelTween?.Dispose();
cancelTween = new CancellationTokenSource();
await UniTask.WaitForEndOfFrame(this); // Tween is actually not cancelled yet!
transform.SetParent(canvas.transform, true); // Tween has been cancelled, now we can do what we want with the tweened object
@kandreyc
Copy link

kandreyc commented Jul 20, 2022

this is my workaround

public static async UniTask ToUniTaskWithImmediateCancel(this Tween tween, CancellationToken token)
{
    await using var _ = token.Register(() =>
    {
        if (tween.IsActive())
        {
            tween.Kill();
        }
    }, true);

    await tween.ToUniTask(TweenCancelBehaviour.Kill, token);
}

@neuecc
Copy link
Member

neuecc commented Jul 21, 2022

Because of Performance (Register has allocations), it is not immediate.
However, I understand the needs, I will try to find a way to implement it efficiently.

@yellowisher
Copy link
Contributor

Another workaround; call tween.onUpdate just after cancel. (quite cumbersome though)

cancelTween.Cancel();
tween.onUpdate(); // Instead of WaitForEndOfFrame
transform.position = Vector3.zero;

Looking forward to neat implementation. 👀

@keenanwoodall
Copy link

keenanwoodall commented Aug 15, 2022

I'm not sure if this is related, but I am running a chain of sequences and passing this.GetCancellationTokenOnDestroy for the cancellation token. If the game-object is destroyed during the first tween, a cancellation exception doesn't seem to be thrown. You can see IsCancellationRequested is true, but execution continues and I get a MissingReferenceException on the transform.
image

@neuecc
Copy link
Member

neuecc commented Aug 16, 2022

use the TweenCancelBehaviour?
default is Kill.
CancelAwait, ***AndCancelAwait are throws OperationCanceledException.

@keenanwoodall
Copy link

I see, thanks. I switched to the ToUniTask extension method so I can set the cancel behaviour, tho I would expect WithCancellation to throw an exception by default :P

@github-actions
Copy link
Contributor

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@vachh
Copy link

vachh commented Apr 22, 2024

mark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants