A simple example of using IEnableableComponent

There was a time in the history of Unity's ECS that we used tag components to control the game logic. For example, when an entity is "active", we add an Active component to it. When the entity becomes inactive, we remove this Active component. What this does then is it makes it easy to query … Continue reading A simple example of using IEnableableComponent

Sorting a million sprites

When I wrote this article in 2020 about rendering a million sprites, I was also writing a 2D rendering framework using this technique combined with DOTS. I was planning to use this framework for Academia: School Simulator. I was not successful then because I found out that the method Graphics.DrawMeshInstancedIndirect() does not respect sorting layers … Continue reading Sorting a million sprites

Accessing IBufferElementData elements in a job struct

I highly recommend using job structs instead of the magical Entities.ForEach for some reasons. However, I think I haven't shown how to access IBufferElementData elements in a job struct like IJobEntityBatch, yet. I'll show you how in this short post. An IBufferElementData is like an IComponentData that can be used to define a certain kind … Continue reading Accessing IBufferElementData elements in a job struct

DOTS Snippets: Populating native collections in parallel

Here we go again writing DOTS code without the aid of Entities.ForEach(). This time, let's tackle something simple but common: populating native collections like NativeArray, NativeList, or NativeMultiHashMap in parallel with Burst enabled. NativeArray Let's start with something very easy. Let's populate an array where the values is just the double of the index (index … Continue reading DOTS Snippets: Populating native collections in parallel

DOTS Snippets: Listening for new and destroyed entities

It's time for another DOTS Snippets! A common operation in games is tracking when something is created or destroyed such that we can execute some operations when they happen. Let's imagine a game example. Say we're making a 2D grid based city builder where each city object (house, building, or road) can be placed on … Continue reading DOTS Snippets: Listening for new and destroyed entities

Why job structs are better than Entities.ForEach()

I started dabbling with Unity's DOTS ever since it came out in 2018. I have used every evolution of its API from [Inject] to IJobForEach then to job structs (chunk iteration) and Entities.ForEach(). There's even a new one now, IJobEntity (haven't explored it yet). To me, job structs are the best. They're more verbose but … Continue reading Why job structs are better than Entities.ForEach()