[Video Tutorials] ECS, Job System, Burst

Hey everyone,
I’ve been doing my own research studying about ECS, Jobs, Burst and making videos covering what I’ve learned so that you can learn too. I’m loving the insane performance benefits the DOTS stack provides.

NOTE: Some of these videos were made in June 2019 but almost all of it is still up to date, check out what changed here: https://youtu.be/JxbvRhxeKTo

If you’re completely new these Getting Started videos should help you understand how things work:


Getting Started with ECS - https://youtu.be/ILfUuBLfzGI
Getting Started with the Job System - https://youtu.be/C56bbgtPr_w
Unity DOTS Explained - https://youtu.be/Z9-WkwdDoNY
Getting Started with Unity DOTS Physics - https://youtu.be/B3SFWm9gkL8

Pathfinding in Unity DOTS! (Insane Speed!!!) - https://youtu.be/1bO1FdEThnU
Pathfinding in Unity ECS! (Epic Performance!) - https://youtu.be/ubUPVu_DeVk
Game Objects with Unity DOTS Pathfinding! (ECS mixed with MonoBehaviour) - https://youtu.be/XomlTHitAug
Dynamic Buffers in Unity DOTS (Array, List) - https://youtu.be/XC84bc95heI
How to Instantiate Prefabs in Unity DOTS (Convert Game Object to Entity) - https://youtu.be/pk-C_h0WJZs
Make games without Code? Visual Scripting! (Unity, DOTS, ECS) - https://youtu.be/nqt3p1n342A
What are Subscenes in Unity? (Massive Worlds!) - https://youtu.be/91kJtsDLTyE
How to handle Events in Unity DOTS! (C# Events from ECS) - https://www.youtube.com/watch?v=fkJ-7pqnRGo
What are Blob Assets? - https://www.youtube.com/watch?v=7_rZhp6V8ds
Complete Game in Unity DOTS! (Free Download) - https://www.youtube.com/watch?v=EhTEn_WB-to

This video is a very nice showcase of what can be done with ECS, here you have a bunch of Marines shooting at thousands of Zombies. You can get the project files from the website.


Battle Marines Vs Zombies - https://youtu.be/fTw_fXsvC6I
Find Closest Target in Unity ECS - https://youtu.be/t11uB7Gl6m8
Find Closest Target with ECS + Jobs - https://youtu.be/nuxTq0AQAyY


How to draw a Simple Sprite - https://youtu.be/6eV9NR3Vb9U
How to get Output from the Job System - https://youtu.be/YBrCR9rUOaA
Simple Sprite Sheet Animation - https://youtu.be/tvi44I_SK3w
Quadrant System (Find Target/Obstacle Avoidance) - https://youtu.be/hP4Vu6JbzSo
100,000 Units Animated in Unity ECS! - https://youtu.be/t1f8ZreCuuQ
Control Units and Give Orders in Unity ECS! - https://youtu.be/3Xjc7NjL0Gc
Make games without Code? Visual Scripting! (Unity, DOTS, ECS) - https://youtu.be/nqt3p1n342A

What are Value Types and Reference Types in C#? (Class vs Struct) - https://youtu.be/KGFAnwkO0Pk

Unity DOTS - What changed? - https://youtu.be/JxbvRhxeKTo

Also I’ve only been researching ECS for a few weeks so it’s possible that some problems have better solutions than what I’ve come up with so if you notice something that doesn’t seem right or there’s a better way of doing please let me know!

Complete Video Playlist:

Resources for your own research:
Official ECS Samples: GitHub - Unity-Technologies/EntityComponentSystemSamples
Official ECS Manual: Entity Component System | Entities | 0.4.0-preview.10
Lucas Meijer Blog: https://lucasmeijer.com/posts/
Game Torrahod Blog: https://gametorrahod.com/tag/unity-ecs/

Unity Talks:
Converting scene data to DOTS: https://www.youtube.com/watch?v=TdlhTrq1oYk
Unboxing DOTS: Designing workflows for humans: https://www.youtube.com/watch?v=VXuR8VVQzwQ
Unity ECS for mobile: Metropolis Traffic Simulation: https://www.youtube.com/watch?v=iCnYm7kRC1g
Overview of physics in DOTS: https://www.youtube.com/watch?v=tI9QfqQ9ATA

A Data Oriented Approach to Using Component Systems: https://www.youtube.com/watch?v=p65Yt20pw0g
Converting your game to DOTS: https://www.youtube.com/watch?v=QbnVELXf5RQ
Data-Oriented Technology Stack (DOTS) and Megacity demo release: https://www.youtube.com/watch?v=kUdHg6GRS24
Leveraging DOTS-powered physics: https://www.youtube.com/watch?v=yuqM-Z-NauU
Understanding data-oriented design for entity component systems: https://www.youtube.com/watch?v=0_Byw9UMn9g
Intro To The Entity Component System And C# Job System: https://www.youtube.com/watch?v=WLfhUKp2gag
Job System & Entity Component System: https://www.youtube.com/watch?v=kwnb9Clh2Is
C# Job System + ECS usage: https://www.youtube.com/watch?v=fp1D45hhVEM

Hope these videos help you learn about the awesome world of ECS+Jobs+Burst.
Cheers!

28 Likes

Really nice job on the videos, are you planning more ESC tutorials.

1 Like

Thanks! Yup, currently working on Sprite Sheet Animation.

Nice tutorials! Keep up good work!
Also I’ve been making a space invaders style game for kata purposes for some time. Hopefully next week I’ll be ready to capture a tutorial about what I’ve learned. I’ve got something funny in my mind to keep people in pace while I am talking about cpu caches and stuff :smile:

1 Like

Thanks! It helps a lot, I was wondering if you plan to do some tutorial about the animation in ecs?

1 Like

Really great vids, thanks, they’ve been a lot of help to me.

1 Like

I’m interested in drawing sprites. I made a totally different way to go about it. I’m managing a single huge mesh. The sprites are then just indeces to four vertices in this single mesh. Before rendering, I transform the vertices of the mesh using the LocalToWorld of each sprite. This is relatively fast when burst is enabled. This way, I can guarantee a single draw call for at least 16,380 sprites using a single material. The only downside is that I have to copy a maintained native array of vertices, uvs, colors into managed arrays so they can be set into the Mesh.

Using a RenderMesh for a sprite atlas means that there would be multiple meshes since they have different UVs. I’m not sure of the effect of this in terms of instancing. Would this result to more draw calls? Would this be faster compared to my method?

1 Like

I’ve been following your ECS videos over the past few weeks. Seriously good work.

I commented a while back on one of your videos saying how it would be good to see a tutorial on the new physics engine. Creating physics bodies from code, object hierarchy and how to manage them in ECS, etc.

1 Like

The video going live later today covers a very simple Sprite Sheet Animation system, should be a great starting point for anyone looking into ECS Animation.

Using a single mesh for animating a bunch of units is something I’d like to research, currently working on testing Graphics.DrawMeshInstanced which also seems like an interesting approach.
Meshes with different UVs do indeed break GPU Instancing however you can still use Dynamic Batching so your approach should provide good results.
The Marines Vs Zombies video uses Dynamic Batching to manage the draw calls, each Unit has its own different mesh.

Yeah Physics is something I haven’t yet researched. Hopefully this week I’ll be able to finish my Animation research and get onto Physics.

Thanks for the comments everyone! Glad you like the videos!

1 Like

New Video: Simple Sprite Sheet Animation in Unity ECS - https://youtu.be/tvi44I_SK3w

Let’s implement the Simplest form of Animation in Unity ECS using Sprite Sheets.
The video covers making a Component to hold Animation data, a System to animate it and another System to render it using Graphics.DrawMesh();
In a future video I will cover using Graphics.DrawMeshInstanced(); to see just how far we can push this.

7 Likes

I like the Sprite animation vid. I’d really love it if Sprite animations worked for ECS, it’s cumbersome translating data back/forth between ECS and GameObjects. But there’s no easy alternative when using large HD Sprites, I need the tightly packed Atlases from huge textures, and the current Sprite / Animation classes don’t seem fit to efficiently translate into ECS.

hello! I’m not sure if you notice the Project Tiny has C# version. That’s fun and seems very helpful to your 2d game!

Nice job.

Would indeed be great to have some functions to access the automatic sprite atlas that Unity generates. If we could get the generated texture and the coordinates of each Sprite that could help make the process easier.

I definitely want to look into Project Tiny in the future, trying to make a really small fully ECS based game sounds like a great challenge.

I’ve been working on getting the most performance out of Graphics.DrawMeshInstanced(); and I’ve managed to get it running with 200,000 individually animated sprites! That’s insane!

Video on how it works coming out this weekend.

1 Like

You can try SpriteUtility.GetSpriteTexture which can give you the atlas texture. Then you can get vertices, triangles and atlas uv coordinates from SpriteRenderer.sprite.
I briefly looked into this to see if I could generate a RenderMesh and material from the Sprite but got stuck cos SpriteUtility is in the Editor namespace and I couldn’t work out how to get the atlas texture at runtime. I didn’t push beyond that with my limited knowledge but I’m sure you’d be able to work it out.

Also looking into Tiny, I notice it has a Unity.Tiny.Core2D.Sprite2D (which is the Sprite component) with the following summary.

There’s also the Sprite2DSystem ComponentSystem in the same file and looks like a good place to start to replicate ecs sprite mechanics. I don’t know if the atlas (Image2D) Tiny uses is at all related to Unity’s sprite atlas though or whether it has its own custom version.
I’m on linux which doesn’t support tiny yet so can’t delve much deeper but you might find useful info there. It all looks pretty cool.

New Video: Quadrant System (Find Target/Obstacle Avoidance) - https://youtu.be/hP4Vu6JbzSo

Let’s make a Quadrant System in Unity ECS to solve problems related to Unit Positions like a Targeting System or Obstacle Avoidance.
It’s a great system for placing Entities into separate buckets for easier searching. Awesome for any kind of algorithm that requires identifying nearby Entities like Find Target or Obstacle Avoidance or as used in the Boids demo.

2 Likes

New Video: 100,000 Units Animated in Unity ECS! - https://youtu.be/t1f8ZreCuuQ

Let’s spawn 100,000 Animated Sprites in Unity ECS!
We’re using Graphics.DrawMeshInstanced(); in order to draw all of our Units. Doing it this way we can massively benefit from the Job System to create various jobs to prepare the data before doing just a few Draw Calls.
The end result in this scene is 100,000 units but if the Sprite sheet is correctly set up to minimize overdraw we can push it past 200,000!

3 Likes

Looking Awesome, but how to deal with different sprites/materials,
also found if you want to move sprites need fix in “SpriteSheetAnimation_Animate” spriteSheetAnimationData.matrix update.

Switching and handling multiple Animations (Walk, Idle) is something I’m currently researching.
What fix do you need to move the sprites? It works fine for me if I just have a System moving the Translation.

public class MoveSystem : ComponentSystem {
   
    protected override void OnUpdate() {
        Entities.ForEach((ref Translation translation) => {
            translation.Value.x += .5f * Time.deltaTime;
        });
    }

}

Hey everyone!
I’m back to making Unity DOTS / ECS Video Tutorials.
Last I touched DOTS was 6 months ago so first thing I did was look at what changed.
Thankfully while things have improved significantly there haven’t been many breaking changes so almost everything in those older videos is still up to date.
Here are the latest videos:

Unity DOTS - What Changed? https://youtu.be/JxbvRhxeKTo

Getting Started with Unity DOTS Physics https://youtu.be/B3SFWm9gkL8

Also related to Unity DOTS, I covered the current state of Visual Scripting
Make games without Code? Visual Scripting! https://youtu.be/nqt3p1n342A

Hope you find the videos useful!

2 Likes