Learn how UniTask can turn your long running operations into an allocation free workflow, completely replacing Coroutines, Asynchronous Tasks and even Unity's new Awaitable class. The feature rich UniTask library can seem overwhelming at first glace, but getting started is easier than you think! With the help of UniTask's extension methods you can convert your entire workflow with minimal effort and start using this efficient allocation free async/await integration for Unity right now.
https://github.com/Cysharp/UniTask
IMPORTANT NOTES:
1) When calling a UniTask, it is preferred to use async UniTaskVoid over using async void in the calling method's signature.
2) Starting from Unity 2022.2, the MonoBehaviour class includes a destroyCancellationToken so you don't need to use the extension method GetCancellationTokenOnDestroy()
3) If you need to await the same UniTask multiple times, use UniTask.Lazy() to manage continuations.
4) There is a known issue with UniTask.WhenAll where it exits early if any task throws an exception, which differs from the expected behavior of waiting for all tasks to complete before handling exceptions. One solution is to use a helper method WhenAllSettled, allowing all tasks to finish, providing a detailed result for each task, including any exceptions.
Issue: https://github.com/Cysharp/UniTask/issues/514
Potential Solution: https://gist.github.com/adammyhre/40e7c968edda098fdebb2adbe806c911
Want to support me? 😀
Buy me a coffee! https://ko-fi.com/adammyhre
🔔 Subscribe for more Unity Tutorials https://youtube.com/@git-amend
Discord: https://discord.gg/FDRZGQBBUC
#unity3d #gamedev #indiedev
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 Coroutines
6:00 Tasks
9:10 Cancellation Tokens
11:54 UniTask
18:10 Async LINQ
21:00 Generic UniTask
22:08 Awaitable
More Useful Code:
https://github.com/adammyhre?tab=repositories
Unity Utility Library: https://github.com/adammyhre/Unity-Utils
Lock Inspector Hotkey: https://gist.github.com/adammyhre/4754f731a93bf1cab0d1385ccfa23642
Assets Shown In This Video (Affiliate Links)
Stylized Nature MegaKit https://quaternius.itch.io/stylized-nature-megakit
Procedural Circular Health and Progress Bars Pro: https://assetstore.unity.com/packages/tools/gui/procedural-circular-health-and-progress-bars-pro-187016?aid=1101lw3sv
Hot Reload: https://assetstore.unity.com/packages/tools/utilities/hot-reload-edit-code-without-compiling-254358?aid=1101lw3sv
Hierarchy Icons: https://assetstore.unity.com/packages/tools/utilities/better-hierarchy-272963?aid=1101lw3sv
Better Transform: https://assetstore.unity.com/packages/tools/utilities/better-transform-size-notes-global-local-workspace-child-parent--276554?aid=1101lw3sv
Better Mesh Filter: https://assetstore.unity.com/packages/tools/utilities/better-mesh-filter-266489?aid=1101lw3sv
Editor Console Pro: https://assetstore.unity.com/packages/tools/utilities/editor-console-pro-11889?aid=1101lw3sv
Any Object Finder: https://assetstore.unity.com/packages/tools/utilities/any-object-finder-286455?aid=1101lw3sv
*Follow me!*
https://linktr.ee/gitamend