The Unity game engine launched in 2005, aiming to “democratize” game development by making it accessible to more developers. Since 2019, the core of Unity is being rebuilt with the Data-Oriented Technology Stack. (DOTS) makes great games run faster on multicore processors without the heavy programming headache.
Ciro Continisio, Lead Evangelist, EMEA -at Unity Technologies, presented a deep dive into the latest tech at Codemotion Milan in 2019 and predictions of what will be possible in the future of game development. Here we cover some of the key points of a jam-packed, fast-paced presentation – you’ll definitely want to what the video for the demos!
What is DOTS?
DOTS provides programmers with a convenient sandbox to write safe multithreaded code for massive performance gains, while also optimizing thermal control and battery life on players’ mobile devices. By moving from object-oriented to data-oriented design, it will also be easier for you to reuse your code and for others to understand and work on it. DOTS involves a number of key benefits to make it easier to create games:
The Burst compiler
The Burst compiler is a code generator/compiler that has been available since Unity 2018.1 as a preview package.
As Ciro explains, “So basically, 90% of the time you don’t really need to do anything with it. Like we do the work for you. And you just compile your C sharp jobs in a very, very optimised way, which depends on the architecture that you’re building for. So if you’re building for a certain type of architecture, the burst compiler compiles in a very optimised way just for that specific CPU.
There’s not really much that you need to do for it, you just apply a tag to your job and your code, and then you use burst compiler.”
Entity component system
In Unity, two basic structures represent every part of a game: the GameObject and the MonoBehavior. Every GameObject contains one or more MonoBehavior, which in turn describes the data (what the object knows) and the behavior (what the object does) of each element in a scene.
With the rise of multithreaded programming, many issues with the GameObject architecture started to become more evident. In response, Unity introduced the Entity Component System (ECS), a new paradigm alternative to the traditional GameObject/MonoBehavior one.
Ciro calls this one of the most important parts of the stack and “one that’s really shaping the future of unity.”
“In ECS, you don’t have game objects anymore, you have entities, but they act more or less in the same way. So any objects in your scene, your character, or a chair in a room, that’s an entity.”
Entity Component Systems have three central parts:
- Entities — the entities, or things, that populate your game or program.
- Components — the data associated with your entities, but organized by the data itself rather than by entity. (This difference in organization is one of the key differences between an object-oriented and a data-oriented design.)
- Systems — the logic that transforms the component data from its current state to its next state— for example, a system might update the positions of all moving entities by their velocity times the time interval since the previous frame.
Introducing Mega City
Unity’s ECS team and two artists from our First Person Shooter (FPS) Sample group produced a futuristic cityscape in just two months– alive with flying vehicles, hundreds of thousands of highly detailed game objects and unique audio sources – to showcase their progress on ECS and the Burst Compiler.
Ciro explained: “It’s a huge CD made of 4.5 million renders. So 4.5 million is a number that in Unity without ECS you will never see that you can write it in textbooks, but 4.5 million objects, you can’t have them, the editor will explode.
But one thing we wanted to achieve with Mega City was we wanted to give artists the power create these buildings, not programme them through a JSON or whatever, they needed to be in the editor and actually play game objects and maybe use prefabs and maybe use nested prefabs, all the power that the editor offers you, we need to make it available to the artists. So what you see here like huge buildings, each one of them is made of 20,000 objects.”
How to create gameplay in ECS?
Ciro shared: “t’s a question that we’re getting more and more as people will explore this. They like it and they’re like, Okay, I understand the tech. But I need to make a game. How do I make it nice?”
Ciro created a small mobile-first game “where you roam around. You fight with these enemies, and you use sub-scenes to compose your scene. And the gameplay is completely driven by DOTS. Not everything is driven by DOTS but the gameplay is. While some of the things which I couldn’t do with DOTS, I’ve done with just regular game objects, and then I make them talk to each other.”
“So the advantages of creating gameplay in ECS is obviously the performance. The code is very reusable. It’s very easy to refactor into debug, because you have a lot of clarity on where things are happening. You have a lot of clarity on the order in which things are happening.”
There are also however disadvantages: “There’s a lot of code to write. When you write code in ECS, you generally need to write more code than in mono behaviour. And most of the code is not your functional boilerplate, the header of the class, the signature of the function. So there is a lot of code to write. And we are working on that we want to provide you with faster and faster ways to write code, potentially generating it for you or shortening the function calls and stuff like that.
The other drawback is that it doesn’t interact with all of the Unity features. And again, that’s something we’re working on. We’re creating them as they as we can because of time and also because we want to create something that’s final, we don’t want to give you something that’s temporary and then we change it down the line.
Where are DOTS headed?
With the new Unity Live Link, you can make changes in the Editor and see the changes reflected on any connected devices running the standalone player. Where you previously had to create an executable, build all the assets, build all your scripts and then upload them to the device each time you wanted to test, you can now test in real-time.
Since iteration speeds are key to the process of creating game worlds, and then tweaking and polishing the user experience, interacting with your game on the actual target device in real-time can make all the difference. Unity Live Link provides on-device performance feedback, enabling you to explore the performance consequences of different choices directly on the device and find the right balance between details and performance.
After you create a Live Link Build, the next time you make changes you can just save your Scene and Unity will bundle your updates and send them to the Live Link Player
As Ciro explains “Now you can make changes on a running game n a phone or on a console. And that’s super powerful. Because now, you’re a designer, and you want to see how it looks on the device. You just like literally save the scene and you have it on the device. Does it look good? Does the shader look good? Does the position of the of these objects make sense? And what’s the impact on the performance, you could be profiling the thing on the device live, and make a change, save and see how the performance changes. Super, super powerful. And it’s only possible because data and logic are separated.
CIro also predicts, there’s going to pop up work opportunities that are related to ECS and DOTS.