A New Way To Program In Unity

Unity has been working hard to provide an alternative way of developing games. It’s called DOTS or Data Oriented Technology Stack and, as the name implies, focuses on Data Oriented Design (DOD) rather than the standard Object Oriented Programming (OOP) approach. In simple terms this technology allows Unity programmers to easily and very efficiently write multithreaded code with massive performance gains!

Normally if you develop a game in Unity, the game runs on one main thread. I like to think that the idea of a thread is quite similar to reading a book. You read the page from top to bottom and you go to the next page once you’ve reached the end. This is how a computer handles a thread too. It reads the code from top to bottom one instruction at a time. Now imagine having 4 readers and you give a quarter of that page to each of them to read. That would be a lot faster!

After reading up on it some more I decided to give it a go. DOTS can be implemented mainly through ECS (Entity Component System), together with Jobs and Unity’s Burst Compiler for maximum efficiency. Below is a nice video that summarizes it pretty well:

The video above covers pretty much everything about ECS right now. It is still in its baby shoes but it has a lot of potential. My test setup involved trying to get as many cubes as possible on screen that follow simple sine movement patterns at 60 frames per second. As a reference keep in mind that about 8000-9000 GameObject cubes would probably hit that limit. Using ECS however, I managed to get a whopping 120000 Entity cubes on screen before almost dropping below 60 frames per second. And that was still in the Unity Editor! I could probably raise that to about 160000 on an actual build.

120000 cubes moving in a sine pattern

If you want to learn more about ECS I recommend this page. It explains everything in much greater detail than I ever could! This technology will definitely make its way into Evergreen but until we reach that point we’re just going to have to deal with object oriented programming for now.