async/await support for Unity with UniRx

Unity Technologies has announced Unity Runtime upgrades to .NET 4.6 and C# 6 and has published the early access build on their forum. That’s great news! I’ve tried it, and UniRx was integrated into .NET 4.6. Today, I released UniRx ver 5.5.0 on AssetStore. It supports async/await and helpers.

Unity 5.5.0xMono-Runtime-Upgrade-1-b4 supports async/await but does not have SynchronizationContext yet. What does this mean?

Image for post
Image for post

After using the await multithreaded method (Task.Delay, Task.Run, etc.), one cannot touch GameObject property because it runs on another thread.

UniRx has introduced UniRxSynchronizationContext, which helps it.

Image for post
Image for post

It is used automatically if one imports UniRx.

UniRx extends GetAwaiter to Unity’s coroutine classes, so it supports await directly.

Image for post
Image for post

And of course, IObservable is awaitable.

Image for post
Image for post

Unity’s async/await support is good enough to integrate existing workflow. I cannot wait! UniRx adds many functions to async/await for Unity, so UniRx is the best library for the async/await era of Unity. Please try it and enjoy it.

Written by

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.

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