Search Unity

[Video Tutorials] ECS, Job System, Burst

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

  1. FF56

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    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.

    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


    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


    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.0/manual/index.html
    Lucas Meijer Blog: https://lucasmeijer.com/posts/
    Game Torrahod Blog: https://gametorrahod.com/tag/unity-ecs/

    Unity Talks:
    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: Jun 7, 2019
    Ryiah, Antypodish, karsnen and 8 others like this.
  2. francois85

    francois85

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

    FF56

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

    m3rt32

    Joined:
    Mar 5, 2013
    Posts:
    60
    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
     
    FF56 likes this.
  5. eterlan

    eterlan

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

    calabi

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

    davenirline

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

    Pendulum_

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

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    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. FF56

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    francois85, cordlc, m3rt32 and 2 others like this.
  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:
    54
    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:
    633
    Nice job.
     
  14. FF56

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    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:
    332
    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. FF56

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    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.
     
  17. FF56

    FF56

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

    bog-imp

    Joined:
    Jul 25, 2012
    Posts:
    38
    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. FF56

    FF56

    Joined:
    Dec 22, 2014
    Posts:
    25
    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. }