Demigiant / dotween

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

Async/Await Support #387

Open Ristellise opened 4 years ago

Ristellise commented 4 years ago

Hello! Decided to create a new issue asking about Async and await support since I found out https://github.com/Demigiant/dotween/issues/145 is over 2 years ago.

Will it be possible to support it now?

Demigiant commented 4 years ago

Hello!

You're right, it's time so I just did it, here you go :) I'm not releasing it on the website yet because the Pro version first needs to be updated to support some API changes (if you have the Pro write me directly here).

The new async methods are myTween.AsyncWaitFor[Completion Rewind Kill ElapsedLoops Position Start]

Demigiant commented 4 years ago

Important note! It requires Unity 2018, not Unity 2017 (because Unity 2018 added a nifty Task.Yield method that allows me to make everything nicer and non-allocating). On older versions the Async methods will simply be missing.

Ristellise commented 4 years ago

Hello!

You're right, it's time so I just did it, here you go :) I'm not releasing it on the website yet because the Pro version first needs to be updated to support some API changes (if you have the Pro write me directly here).

The new async methods are myTween.AsyncWaitFor[Completion Rewind Kill ElapsedLoops Position Start]

Thanks for the async support! The link seems to be broken so here it is.

Demigiant commented 4 years ago

Ouch, sorry, and thanks, fixed it in the original post too :)

DmitriyYukhanov commented 4 years ago

Hey Daniele @Demigiant !

Looks like it does not works when .NET Standard 2.0 enabled: image

To make it work, just replace NET_4_6 with (NET_4_6 || NET_STANDARD_2_0) at the DOTweenModuleUnityVersion.cs ^^

Also note, 2020.2 comes with C# 8 now and it may break something too, might worth additional checking %)

neuecc commented 4 years ago

My UniTask library adds support of await DOTween with zero(less) allocation. https://github.com/Cysharp/UniTask#external-assets

Demigiant commented 4 years ago

Fixed :)

Matthew-J-Spencer commented 3 years ago

Seems to freeze my Unity instance (requiring full exit) whenever I try to use 'AsyncWaitForCompletion'. For example: await transform.DOMove(cell.Location, MOVE_SPEED).SetEase(Ease.InOutQuad).AsyncWaitForCompletion();.

I'm using Unity 2020.2.1f1 and DOTween 1.2.420. I've been waiting for async/await for years so I'm super pumped about this!

Demigiant commented 3 years ago

Ahoy! That means an error happens. Could you find it and write it to me here?

Matthew-J-Spencer commented 3 years ago

Call me crazy, but after putting my Unity session into debug mode to find the error, it all magically works.

Matthew-J-Spencer commented 3 years ago

Sorry to rehash this again after so many months, but I've come across the exact same problem in another project. Unity freezes up requiring an alt+f4. Calling it like so: await transform.DOMove(pos, SpeedPerUnit).SetSpeedBased(true).SetEase(Ease.Linear).AsyncWaitForCompletion();

Pieg2lTTGI

codemonkeynorth commented 2 years ago

[updated: just realised you're not using the UniTask version but it should equate]

hi @Matthew-J-Spencer did you find a solution?

I had a similar problem but not with AsyncWaitForCompletion

I'm not sure what caused my crash but one of my lines was

await dialogText.DOFade(0, 0.5f)
                .OnComplete(() => isTextDisplayed = false)
                .ToUniTask(cancellationToken: cts.Token, tweenCancelBehaviour: TweenCancelBehaviour.Complete)

for now I've removed the await and added Forget() on the end, in case it was that

dialogText.DOFade(0, 0.5f)
          .OnComplete(() => isTextDisplayed = false)
          .ToUniTask(cancellationToken: cts.Token, tweenCancelBehaviour: TweenCancelBehaviour.Complete)
          .Forget();

// replacement for await on DOTween
while (isTextDisplayed)
{
     await UniTask.Yield(cancellationToken: cts.Token);
}
isTextDisplayed = false;

I'm not actually sure this doesn't crash yet as I've got a bunch of interacting systems and don't know where the problem occurred, but I'm thinking it's a similar issue to yours

Matthew-J-Spencer commented 2 years ago

I found it was not a problem with dotween but a problem with async in the editor. I could change unity versions and it'd work just fine. I remember also running it without debugging allowed it to continue successfully too.

I also tried it without dotween and just a basic async function and I could replicate the freeze.