Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Entity Component Systems & Data Oriented Design In Unity (Article)

Discussion in 'Entity Component System' started by Life_Is_Good_, Aug 19, 2018.

  1. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    Hi!

    I've written a not so short article on Unity's implementation of an Entity Component System (ECS) model & Data Oriented Design (DoD). No pre existing knowledge about ECS or DoD is required by the reader.

    The article handles the principles of ECS, DoD, contains a small custom documentation about the fundamental concepts of Unity's ECS as well as a start guide, where I show the reader how to rewrite a tiny game in ECS fashion.
    Lastly, I've added a critical comment on Unity, discussing their work & claims.

    Of course, this is a lot of input. You can jump through the article as you wish.

    You can find the article as well as the Unity project on my GitHub profile
    https://github.com/LifeIsGoodMI/ECS-And-DoD-In-Unity

    Apparently, GitHub's PDF viewer doesn't support hyperlinks. So, you would probably have to open the PDF in your browser to use that.
     
    Lazulite, xman7c7, Roni92pl and 8 others like this.
  2. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Thank you, think many will enjoy this :)
     
    Life_Is_Good_ likes this.
  3. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Great article. One initial comment, the performance gains are greatly understated. Mostly because the samples provided don't use C# jobs and don't use Burst.

    The performance gains are really about combining DataLayout via ECS, Significantly improved code-gen via burst, and parallelism via C# jobs.

    Is it an unfair comparison to use all 3? Probably, but realistically if you want to have multithreading with OO approaches it is incredibly hard to do. Where as in ECS it is quite easy to write jobified code by default.

    Especially datalayout and codegen (SIMD in particular) go hand in hand, because great datalayout with S*** codegen rarely gives gains and the other way around. Only if you get both right do you remove all bottlenecks and great performance as a result.

    I agree on some of the comments about injection being used too much. I think generally ComponentDataArray was not the best choice. IJobProcessComponentData & ArchetypeChunk is at least internally what we are using mostly now.
     
    Zoey_O, Vacummus, Roni92pl and 4 others like this.
  4. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    Thanks for your replies!

    Oh definitely, I completly agree there. However, I found myself already at around 9000 words, so I thought introducing the Job System within the same article would be a bit overkill.
    That being said, I think this is even more impressive for the user. My samples still run on a single core as you said, there's no ahead-of-time compilation and all those other benefits that come with the new Burst compiler. This huge performance gain is the result of nothing but restructuring your code & data.

    As I mentioned in my critique, of course it's not perfect (there simply cannot be a perfect solution) but I absolutely love your work & it is great to see how open you are to critique. Keep it up!
     
    psuong and LazyMonkey like this.
  5. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    I have just updated the repository. I felt like this huge pdf file was a bit overwhelming. So, I've outsourced the 3 big topics (article, documentation, start guide) into separate pdf files. Also included a neat little ingame picture :)
    https://github.com/LifeIsGoodMI/ECS-And-DoD-In-Unity
     
    SugoiDev likes this.
  6. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    And in preview.10 Scale exists now (is about 5.1 paragraph) :)
     
  7. LazyGameDevZA

    LazyGameDevZA

    Joined:
    Nov 10, 2016
    Posts:
    143
    @Life_Is_Good_ why not just write the articles in regular Markdown on GitHub? That should still allow you to hyperlink to other files etc. I think these are a great resource of information for people to understand things a little better.
     
  8. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    Yep, I'm going to adjust the paragraph, but I'll leave it in their nevertheless. Maybe someone wants to avoid those components for some reason.

    To be honest, I just really haven't thought about it. I just started writing some stuff down in word and later continued to do so. I might try to copy the stuff over.

    Thanks!
     
  9. Life_Is_Good_

    Life_Is_Good_

    Joined:
    Mar 4, 2013
    Posts:
    43
    #bump, because I think it's pretty relevant right now.