UniRX vs UniTask

Emre SOLAK
Dream Harvesters Team
2 min readJul 27, 2022

I’ve been using both these frameworks for some time. It’s very easy confusing while using both as someone can have very similar outcomes from the both frameworks. You can have the same outcome with UniTask as you’d get with UniRX and vice versa.

That’s why i wanted to clarify the differences between the frameworks and tell about how i use them.

UniRX is a functional/declarative reactive extension. It’s a port of .net reactive extensions. Reactive programming is a paradigm focusing on the stream of data. We interpret everything as a sort of stream and build the flow based on the changes of this stream. OOP, on the other hand, structures based on the the states and hierarchies of objects and runs a program based on the instruction set instead of the changes in the streams.

UniRX is based on Observer pattern and implements many of the reactive operators and some specific operators for Unity3D. These unity specific operators are also some workarounds for the known limitations in Unity3D. For instance adding instead of adding Update method to all scripts, you can use Observable.EveryUpdate which implements a manager and mediates Update logic from this manager. This is much more efficient than using Update methods in the scripts.

UniTask is a library for async programming model in Unity3D. While it’s possible using plain await/async in the scripts, UniTask introduces more specific implementations to Unity3D which is more efficient than using the plain ones. UniTask also introduces some helpers for the Unity like DelayFrame.

Async programming model tries to simplify multi-threaded programming. .Net used to have different models for async tasks. The latest is Async programming model with async/await keywords. I’ll not dive into the technical details but the main purpose is being able to assign tasks to worker threads, keeping the app as responsive as possible by leaving main thread lazy. Async programming model is a simplified way of managing these work allocation, thread management so programmers can focus on the product instead of technical details.

After these explanations, it’s clear that even if you can have the same logic with both these frameworks/approaches, their main purpose is totally different. UniRx is a reactive extension to be able to interpret the logic in reactive way, UniTask is an async programming library.

While UniRx allows use organize the relation between classes based on changes in the data and stream, UniTask allows you implementing logic in async easier.

Sometimes i find myself in a situation trying to use which because i generally have both in my projects.

In these situations i ask myself

  1. If this is about the change in data
  2. If this is a task that needs to be done in parallel

Answer of these questions tells me what to use pretty much.

--

--

Emre SOLAK
Dream Harvesters Team

Co-Founder @Teknodev & @DreamHarvesters / Senior Developer / Expert on Game Development and Project Management