UniTask v2 — Zero Allocation async/await for Unity, with Asynchronous LINQ

  • Callback process still remains
  • Can’t use try-catch-finally because of the yield syntax
  • Allocation of the lambda and the coroutine itself
  • Difficult to do cancellation process(coroutine only stop, not call dispose)
  • Impossible to control multiple coroutines (serial/parallel processing)
  • await support for each Unity’s AsyncOpeations
  • Unity’s PlayerLoop-based switching process (Yield, Delay, DelayFrame, etc…) allows for all the functionality of a coroutine on UniTask
  • await support for MonoBehaviour events and uGUI events
  • Zero-allocation of the entire async method to further improve performance
  • Asynchronous LINQ(UniTaskAsyncEnumerable, Channel, AsyncReactiveProperty)
  • Increased PlayerLoop timing (new LastPostLateUpdate will have the same effect as WaitForEndOfFrame)
  • Support for external assets such as Addressables and DOTween

Principle of AsyncStateMachine and Zero Allocation

  • Task Allocation
  • Boxing the AsyncStateMachine
  • Allocation of the Runner encapsulating the AsyncStateMachine
  • Allocation of delegate for MoveNext

Coroutine and PlayerLoop

Asynchronous LINQ

Enhanced await support

.NET Core

Conclusion

--

--

--

a.k.a. neuecc. Creator of UniRx, UniTask, MessagePack for C#, MagicOnion etc. Microsoft MVP for C#. CEO/CTO of Cysharp Inc. Live and work in Tokyo, Japan.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Don’t Get Stuck! Overcoming Starting Block

Schedule automated backups(Linux) privately to github in 3 simple steps

Hosting a Secure Website on EC2 with GoDaddy Domain and SSL Certificate

(Android) 修改Application Id

The Complete Developer’s Guide to Git

CS371P Spring 2021 Week 10: Irena Lee

Ignore Files In Gitignore Using Globbing Patterns

Introduction to NumPy

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yoshifumi Kawai

Yoshifumi Kawai

a.k.a. neuecc. Creator of UniRx, UniTask, MessagePack for C#, MagicOnion etc. Microsoft MVP for C#. CEO/CTO of Cysharp Inc. Live and work in Tokyo, Japan.

More from Medium

DFrame — Distributed load testing framework for writing test scenarios in C#

Checking Barotrauma with the PVS-Studio static analyzer

Active-Passive Background Service In .Net 6

How in MediatR we can have events (Notifications) async and completely real Parallel

How in MediatR we can have events (Notifications) async and completely real Parallel