Search Unity

  1. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[Video Tutorials] ECS, Job System, Burst

Discussion in 'Data Oriented Technology Stack' started by CodeMonkeyYT, May 31, 2019.

  1. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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:
    https://www.youtube.com/playlist?list=PLzDRvYVwl53s40yP5RQXitbT--IRcHqba

    Resources for your own research:
    Official ECS Samples: https://github.com/Unity-Technologies/EntityComponentSystemSamples
    Official ECS Manual: https://docs.unity3d.com/Packages/com.unity.entities@0.4/manual/index.html
    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!
     
    Last edited: Mar 1, 2020
  2. francois85

    francois85

    Joined:
    Aug 11, 2015
    Posts:
    1,237
    Really nice job on the videos, are you planning more ESC tutorials.
     
    CodeMonkeyYT likes this.
  3. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    Thanks! Yup, currently working on Sprite Sheet Animation.
     
  4. m3rt32

    m3rt32

    Joined:
    Mar 5, 2013
    Posts:
    73
    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 :D
     
    CodeMonkeyYT likes this.
  5. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    119
    Thanks! It helps a lot, I was wondering if you plan to do some tutorial about the animation in ecs?
     
    CodeMonkeyYT likes this.
  6. calabi

    calabi

    Joined:
    Oct 29, 2009
    Posts:
    124
    Really great vids, thanks, they've been a lot of help to me.
     
    CodeMonkeyYT likes this.
  7. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    645
    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?
     
    CodeMonkeyYT likes this.
  8. Pendulum_

    Pendulum_

    Joined:
    Jul 30, 2015
    Posts:
    125
    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.
     
    CodeMonkeyYT likes this.
  9. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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!
     
    eterlan likes this.
  10. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
  11. cordlc

    cordlc

    Joined:
    Jul 27, 2018
    Posts:
    11
    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.
     
  12. eterlan

    eterlan

    Joined:
    Sep 29, 2018
    Posts:
    119
    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!
     
  13. francois85

    francois85

    Joined:
    Aug 11, 2015
    Posts:
    1,237
    Nice job.
     
  14. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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.
     
    eterlan likes this.
  15. jooleanlogic

    jooleanlogic

    Joined:
    Mar 1, 2018
    Posts:
    364
    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.
     
  16. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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.
     
    pal_trefall and laurentlavigne like this.
  17. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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!
     
  18. bog-imp

    bog-imp

    Joined:
    Jul 25, 2012
    Posts:
    42
    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.
     
  19. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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.
    Code (CSharp):
    1.  
    2. public class MoveSystem : ComponentSystem {
    3.    
    4.     protected override void OnUpdate() {
    5.         Entities.ForEach((ref Translation translation) => {
    6.             translation.Value.x += .5f * Time.deltaTime;
    7.         });
    8.     }
    9.  
    10. }
     
  20. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    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!
     
    pal_trefall and pm007 like this.
  21. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    pal_trefall and Flipps like this.
  22. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    pal_trefall and Flipps like this.
  23. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    184
    How do you deal with the changes to the DOTS-oriented technology stack? Do you keep track of what is outdated and update your older videos?
     
    Last edited: Jan 18, 2020
  24. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    I made a lot of videos back in May and when I came back to DOTS a couple of weeks ago the first thing I did was look at what changed. Thankfully there haven't been many breaking changes so for the most part pretty much everything in those older videos is still accurate.

    I covered what changed in this video: Unity DOTS - What Changed? https://youtu.be/JxbvRhxeKTo
     
    Nyanpas likes this.
  25. runner78

    runner78

    Joined:
    Mar 14, 2015
    Posts:
    195
    I would very much like to see a tutorial about subscenes.
     
  26. Radu392

    Radu392

    Joined:
    Jan 6, 2016
    Posts:
    208
    Code Monkey, it was thanks to you I heard and learned about ECS in the first place. Many thanks for your videos! I had to take a break from ECS to focus on other ongoing projects and could never find any time to learn about subcenes, so if you made a video about that, that'd be great.

    More specifically, it would be cool if you could talk about the advantages and disadvantages of using subscenes against a pure approach and a game object approach.
     
    Last edited: Jan 18, 2020
    CodeMonkeyYT likes this.
  27. YosemiteMark

    YosemiteMark

    Joined:
    Jul 18, 2017
    Posts:
    1
    Please keep these videos coming - they are one of the best learning resources on DOTS out there!
     
    CodeMonkeyYT likes this.
  28. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    184
    Very much the same. ;w;
     
    CodeMonkeyYT likes this.
  29. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    Here's a new video that while not directly related to Unity DOTS it is very relevant due to the necessity to use Structs over Classes
    New Video: What are Value Types and Reference Types in C#? (Class vs Struct)




    Yup Subscenes is definitely something I'd like to research, I haven't looked at them at all yet.

    Thanks for the kind comments everyone! Stay tuned for tomorrow's video covering Pathfinding in DOTS!
     
    Flipps likes this.
  30. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
  31. Curlyone

    Curlyone

    Joined:
    Mar 15, 2018
    Posts:
    41
    Love your tutorials, and your tutorials got me addicted to ECS :D:p

    Thank you^^
     
    CodeMonkeyYT likes this.
  32. lloydv

    lloydv

    Joined:
    Sep 15, 2015
    Posts:
    52
    Great videos. These are a blessing because it is so hard to find up-to-date information.
    One suggestion I have: please post what ECS-related package versions you are using in the youtube description.
     
    CodeMonkeyYT likes this.
  33. JakHussain

    JakHussain

    Joined:
    Oct 20, 2016
    Posts:
    285
    If you are looking into making a video on sub scenes, may I also suggest including a bit / making a follow up video on how DOTS blob asset serialisation works and how you would use it to create save data?
     
    CodeMonkeyYT and Sarkahn like this.
  34. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    New Video: Pathfinding in Unity ECS! (Epic Performance!) - https://youtu.be/ubUPVu_DeVk



    Let's take our Unity DOTS Pathfinding and apply it to Unity ECS so we have Entities roaming around calculating their path.

    Yeah I started including a shot of the Entities Package Manager in the videos, these last ones were made with 0.4 and the next one is with 0.5, no syntax changes.
     
  35. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
  36. Games4Stream

    Games4Stream

    Joined:
    Jan 11, 2020
    Posts:
    5
    Those videos are amazing! Thank you so much!
     
    CodeMonkeyYT likes this.
  37. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
  38. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    pal_trefall and JakHussain like this.
  39. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    pal_trefall and JakHussain like this.
  40. CodeMonkeyYT

    CodeMonkeyYT

    Joined:
    Dec 22, 2014
    Posts:
    61
    JakHussain and pal_trefall like this.
unityunity