Just a few days ago, Unity finally released support for DOTS(Data Oriented Technology Stack) in the most recent unity editor LST release, 2021.3.4f1. This is great news because now we can use more advanced C# 8&9 features within the DOTS environment as well as a host of awesome changes to some of DOTS. This shows that Unity is still dedicated to creating the best data oriented system that they can, to keep unity competitive for years to come.
Unity’s DOTS allows developers to create freakishly performant games by default. These games within the DOTS ecosystem, can achieve several orders of magnitude greater performance by taking advantage of multithreading and tightly packed memory for blazing access speed to the data that is needed.
There is a major trade off for this god tier performance, however. You have to completely change the way you think about programming games. shift to a new paradigm. Data Oriented Design(DoD). Most of us cut our teeth on OOP so it can seem intimidating to completely rewire our brains work, but if you want this performance, you have to make the leap.
Here is a free, unity recommended book on DoD. Click here
It’s possible to use just a few pieces of DOTS in your game, like the C# Job system and the burst compiler, but these won’t see you through to the full power that DOTS offers.
Before we jump into setting up a project, let’s take a cursory look at what makes up DOTS.
The Burst compiler compiles to highly optimized, native code based on whatever platform you are targeting.
The ECS is comprised of Entities, Components, and Systems. I won’t get into ino how these work in this article, as it is beyond the scope, but I will definitely touch on this in the future. Basically, we structure the game into these three categories to achieve maximum memory efficiency, Well beyond what can be achieved with OOP.
The C# Job System allows us to write SAFE, multithreaded, easy to maintain code. It also helps to reduce battery consumption and heat, especially on mobile phones. The major problem with multithreading are race conditions, where you are relying on something you don’t know when will happen. The Job system completely eliminates this problem.
Time to set up, and build a project using DOTS!
Make sure you have downloaded the newest LST version of the Unity editor. 2021.3.4f1 and be either in HDRP or URP. DOTS won’t work on normal 3D.
Now, with DOTS, we have to install a bunch of packages. Luckily there are a few shortcuts we can take to get it done a little easier.
Head to the package manager and selecting the “+” and then import from git URL and type in com.unity.rendering.hybrid. This will install pretty much everything we will need thorough dependencies. Burst, Job system, and the ECS and a platforms package for building as we have to do this a bit differently than normal building.
You may be prompted to restart the editor, make sure you do so.
Once you got all of that imported, you should now see a DOTS option on the top panel of Unity.
You’re running with DOTS now!
Now let’s make sure we can build. We need to create a “Build Configuration” asset to build from. Head to the project window and right click on assets and go to “Create” and then select “build configuration” and then “empty build configuration”
So there is apparently a UI bug with the building process but I found a workaround. Make sure you are in the “Default” layout for the Unity Editor that should solve some of the problems. Once you’ve done that, click into the asset that was just created and name it “base”. The build configurations are able to inherit from each other so you can make changes to the “base” and the changes will appear in the rest of the build profiles.
Your build configuration should look like this. Click add component and we’re going to add a few things.
Ok this is going to be the hardest part of this because of the UI bug but Unity should fix it soon. We are on the cutting edge here, folks.
This is what we want the build config to look like
There are SUPPOSED to be dropdowns to select what you want, but we have to pretty much click blindly. What you want to do is click “Global” once and then click “Classic” until you get classic build profile and then click “Common” until you get general settings and Scene list. I really hope they fix this soon.
Add the current scene to the scene list and you are ready to build!
Thanks for reading.