Search Unity

DOTS runs futuristic Megacity on mobile

A Unity developer case study: How Nordeus adopted DOTS to dramatically change their coding – and create the mobile version of Megacity

What inspires wow-factor demos like Megacity at Unity community events? Are they just eye-candy or are there real benefits for Unity developers? Belgrade-based Nordeus has been a featured studio at many Unite developer conferences, demoing work drawn from their hit games. But their cutting-edge clips aren’t about showing off – they’re about demonstrating new Unity capabilities that will dramatically change what you can achieve both creatively and programmatically.

The project

Regularly demonstrate the latest evolution of our “Performance by default” / DOTS initiative

The goal

Improve multithreaded code performance for all Unity developers

Platforms

Android, iOS, PC

Team members

3 for Megacity, 20 for Battle Demo

Location

Belgrade, Serbia

With CPUs trending towards more and more cores, high-performance multithreading is an essential feature of any modern computing engine. The Unity solution to multiple cores and threads is the Data-Oriented Technology Stack (DOTS), an umbrella term for the Entity Component System (ECS), the C# Job System, and the Burst Compiler.

Consistently wowing Unite audiences from Los Angeles to Berlin, Nordeus has demonstrated the benefits of these and other Unity features such as the Lightweight Render Pipeline (LWRP) and nested Prefabs.

The results:

  • Easy-to-write and efficient multithreaded code
  • Optimized rendering for lower-performance platforms like mobile
  • Faster QA with substantially fewer integration bugs
Connecting DOTS at a hackathon

A fiercely creative and international team

Founded in 2010 by ex-Microsoft engineers Branko Milutinovic, Milan Jovovic, and Ivan Stojisavljevic, Nordeus first published Top Eleven – Be a Soccer Manager (“Football” outside the US), a freemium team-management game. It was enormously successful on Facebook, becoming profitable in three weeks, and was ported to Android and iOS in 2011. Since then, the company has published Golden Boot on iOS and Android, has Heroic: Magic Duel in soft launch, and numerous other games in development stages.

Nordeus has drawn talent from 22 countries to its headquarters in Belgrade, a locale extraordinarily rich in culture and history. They’re routinely cited as a top workplace in Europe and are known as generous contributors to a number of philanthropic organizations.

Two of their top software engineers are Belgrade locals: Jozef Oros and Srdja Stetic-Kozic, who work in the Nordeus Central Tech team with eight others. They are responsible for fostering the tools and techniques used in all Nordeus games, and as Srdja notes, “All of our games are made in Unity.”

Connecting DOTS at a hackathon

“As soon as we heard about DOTS, we contacted Unity to try it out and see if we could collaborate,” said Jozef. “We always want to give our players the best possible user experience, and smooth gameplay is a big part of that. Naturally, we’re especially interested in anything that can help our games run faster.”

The collaboration started with a meeting in Belgrade between the Unity and Nordeus CTOs. Nordeus welcomed help in getting familiar with the new technologies, and Unity wanted a real-world application that would test DOTS to its limits. Srdja added, “We also wanted to make something cool and epic to be showcased by Joachim Ante (a Unity co-founder). So for Unite Austin (2017), we thought ‘let's take a Heroic: Magic Duel battle, supersize it to 100K units, and then blow them all up!’ It was super exciting for us.”

Jozef and Srdja were the first DOTS users at Nordeus. They estimate having spent 90% of their time writing gameplay systems, in particular for rendering, unit movement, and logic. Jozef said, “Unity’s DOTS lets us make some really cool spells that explode at scale – effects that we knew would blow the audience’s minds.”

The team completed the Nordeus Battle Demo for Unite Austin in two months, with the first four weeks devoted to programming and prototyping. They spent one of those weeks in Copenhagen with a Unity team, working together hackathon-style in one room. “Sitting with Joe and his team was an awesome experience. We learned, direct from the source, a tremendous amount about ECS, the C# Job System, the Burst Compiler, and data-oriented programming in general,” Jozef added.

Saying goodbye to object-oriented programming

Moving to data-oriented programming is a significant shift and can appear intimidating at first. However, according to Srdja, “DOTS is really a different way of thinking, but within a week or two it finally clicked and we were able to write much better code. And when we do have to integrate old code, ECS lets us do that quite easily.”

An integral part of DOTS is the C# Job System that writes thread-safe code, manages race conditions (threads running in unexpected order, causing unexpected results), and optimizes context-switching to gain almost 100% usage of multiple cores. Another component is the Burst Compiler, an LLVM-based, math-aware compiler technology that takes C# jobs and produces highly efficient machine code optimized for the particular capabilities of the target platform.

According to Joachim Ante, “Our Burst Compiler understands math and geometry on a deep level and it can perform math optimizations that other compilers just don’t do. It automatically vectorizes C# code and generates these vectorized instructions for a specific target platform. As a result, code can run much, much faster.” The Burst Compiler also eliminates a significant number of integration bugs that would typically have to be weeded out in QA.

Winning the battle for Megacity

The Battle Demo shown at Unite Austin used components from Heroic: Magic Duel. The Nordeus team applied its DOTS expertise primarily on dynamic gameplay elements, with huge numbers of animated units on a limited-size terrain.

This paved the way for its next challenge, as Nordeus took on Megacity, which is a big, open world with 4.5 million objects that need to be rendered, culled, and loaded, 5,000 flying cars needing to be simulated, and 100,000 audio sources that had to be played simultaneously. And all of this needs to work on mobile as well as PC. Jozef said, “For Megacity, Unity’s DOTS was used for everything, like new rendering and animation techniques, UI systems, and even audio. We can use all of this in our existing games, as well as those in development.”

LWRP helps put a metropolis on mobile

Joachim Ante’s keynote address at Unite LA 2018 included an astonishingly complex live demo from Megacity. The demo contains 4.5M mesh renderers, 5,000 dynamic vehicles and 200,000 unique building objects. The vehicles fly on spline-based traffic lanes, never colliding, and there are 100,000 unique audio sources, including neon signs, air-conditioning fans, and cars producing unique sounds to form a rich, realistic audioscape. And it all runs smoothly on smartphones.

“For the Megacity demo, we wanted to show our complex graphics on a mobile version with a very fast frame rate. We used LWRP plus a few custom shader tweaks to make it resemble the PC version as much as possible,” said Jozef. Srdja added, “When you are working on a game that is supposed to stretch the limits of PCs, and then you decide to port it to mobile later, you usually have to rework large parts of it due to performance limitations of mobile platforms. This was not the case with Megacity. DOTS enabled us to use the exact same code running gameplay logic and rendering on a PC and seamlessly scale it down to mobile platforms.”

The Unity Lightweight Render Pipeline optimizes real-time performance on mobile devices by making tradeoffs with lighting and shading. It performs single-pass forward-rendering with one real-time shadow light and light culling per-object (with all lights shaded) in a single pass, minimizing draw calls.

Nested Prefabs and diving into DOTS

“The Megacity demo was also our first encounter with the new Unity nested Prefabs system, and our artists really loved it,” according to Jozef. For example, with nested Prefabs, a large building can comprise many room Prefabs, which in turn can comprise multiple furniture Prefabs, and so on. Developers can split up Prefabs into multiple entities for greater efficiency, reuse any content, small or large, and work on different parts of content simultaneously.

The Nordeus product roadmap is ambitious, with a 100% commitment to Unity and the DOTS approach to coding. As Srdja says, “If you’re thinking about adopting Unity DOTS, just dive in. And don’t be afraid to unlearn a lot of what you know about object-oriented programming!”

“DOTS is really a different way of thinking, but within a week or two it finally clicked and we were able to write much better code. And when we do have to integrate old code, ECS lets us do that quite easily.”

Srdja Stetic-Kozic, Senior Software Engineer

“As soon as we heard about DOTS, we contacted Unity to try it out and see if we could collaborate. We want to give our players the best possible user experience, and smooth gameplay is a big part of that. Naturally, we’re especially interested in anything that can help our games run faster.”

Jozef Oros, Software Engineer

We use cookies to ensure that we give you the best experience on our website. Click here for more information.