Search Unity

What are some Do/Don't, Can/Can't of the ECS and Job systems? (plus personal question)

Discussion in 'Entity Component System' started by MostHated, Sep 16, 2018.

  1. MostHated

    MostHated

    Joined:
    Nov 29, 2015
    Posts:
    1,235
    Hello all,
    This something of a two-part post. The first part is: I tried to see if I could find a list or some explanations of what would be some of the best things in which to use ECS/Jobs, or maybe some systems/individual things in which could use it that people who might not know much about it had not thought about. Then also what would be some examples of bad, not doable, or things that are just not worth it in case someone is considering spending the time to convert something over only to find that it just doesn't help or make a difference. It would be good to hear some of you guys experience in what ends up being good/bad use cases for those of us who are wanting to try and adapt our systems to it.

    Which leads me to part two of my post which pertains to something I was just about to attempt but could not find an answer if I could or not, or if it would be a good idea. I wanted to see if I could convert some of the systems I have made in my current game to use it, but I wasn't sure if it were even possible because of how the characters and vehicles in my game are set up. The primary system in question is an A* based navigation/pathfinding system in which both the pedestrians and vehicles each have a component on them that requests a random waypoint from the pathfinding system as a destination, then asks it to create and then return a path (just a list of waypoints) to that destination from its current location and then handles the movement, keeping track of its current and next waypoints, what speed it should be going, etc.

    The component is slightly different for the pedestrian and the vehicle, the pedestrian version includes access to the parents animator in order to make the character walk/run when moving him or play idle animations while stopped and also some code for enabling/disabling the PuppetMaster asset at certain times so that it is not constantly calculating all of its physics/collider stuff when not necessary. Movement and rotation are handled via this code so that the characters still are able to be influenced by outside forces :

    Code (CSharp):
    1. self_transform.position += self_transform.forward * currentSpeed * Time.deltaTime;
    2.             RotateTowardsDest(currentWaypoint.transform.position);
    The vehicle version is mostly the same minus having an animator or PuppetMaster but it does include a small list in which I have each of the vehicle's wheels and then included in the movement part of Update() I have the following which just rotates the wheels:

    Code (CSharp):
    1.             foreach (GameObject wheel in wheels)
    2.             {
    3.                 var spin = wheel.GetComponent<Transform>();
    4.                 spin.Rotate(spinSpeed / 60 * 360 * Time.deltaTime, 0, 0);
    5.             }
    As I mentioned, what I wanted to do was take this system and see if I could move it over to ECS/Jobs but I am just not sure if that is something I will be able to do. Each character uses Final IK as well as PuppetMaster so that as they are out and about walking around they can be knocked over, pushed around by objects and forced to stumble or fall over and then continue back on their way.

    Pretty much all or most of the demos/examples I have seen seem to use no animation on whatever is a part of the ECS, let alone having something like Final IK or PuppetMaster on it as well. The main thing I am after is being able to simply have more vehicles and pedestrians if possible, or even just increase the performance of the ones I have already but it is important that the pedestrians have FIK and PM still as it is a big part of my game. As I mentioned, it is usually disabled from working and the pedestrians are just walking around but it is still always there and turns on based on proximity to certain things and turns back off after they return to a normal walking state.

    So essentially what it comes down to is, would it even be possible for me to take this system and convert it to use ECS/Jobs? If so, what would be a good approach in trying to start?

    Thanks all!
    -MH
     
    florianhanke likes this.
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I'm in a similar situation with your broader questions.
    I started up a new project last weekend to experiment and maybe finally make the jump to learning ECS.
    I've seen the youtube talks and such a few times and I understand the broad idea of restructuring your code this way, and don't find it too difficult to wrap my head around this new structure.
    The idea was to simulate a crowd in a city block wandering about with traffic, something that would probably be a good use case of ECS since you're dealing with so many agents.
    I was under the impression that I could implement a first rudimentary version with Unity's navmesh and couple that to some ECS components similar to the built-in NavmeshAgent, but as far as I can see everyone who's doing ECS pathing rolls their own a*-based solution.
    I'm not exactly a hardcore programmer, more of a tech artist/hobbyist, so taking a dive into a* seems a little excessive to me for now.

    Sidenote: the introduction to ECS videos Unity hosts in their tutorial sections seem already out of date. When I was attempting to follow them I got compilation errors when marking job parameters as ReadOnly, among others...

    A major issue is simply not knowing what Unity systems can and can't be used with ECS at the moment, or even how you'd do so. The most reliable info on this is watching all the big Unite talks which are outdated in a matter of weeks after posting.
    The roadmap does point out areas where integration with ECS is being done within the engine, but finding more info on this isn't easy. For example, according to the roadmap in 2018.2 an Animation Stream API was added for the job system, which at first glance might make you hopeful it'd mean Animators could soon be controlled by ECS code.
    There's no Unity resources showing it being used as far as I've seen though, and the documentation shows it has something to do with Playables (which is a feature Unity seems to almost NEVER highlight or use. It's been here for a while but who's using it? What's it even useful for? I've read the Playables documentation a few times and I just don't get what it's supposed to be used for.)
    I've barely begun with this project but with the scarcity of (up to date) info on how to use ECS making it almost a requirement to find your answer on the fora (which rarely is the place to be for easy "ECS 101: how to begin using this" guides and serves much more for specific problems and discussions), I'm almost convinced it's better for me to wait until 2019 when ECS might no longer be experimental...

    That's kind of my gripe with the 2018 cycle in general. There's a lot of incredible new stuff that you should try and learn as soon as possible (ECS and SRP mostly come to mind), but a LOT of it is still highly experimental and actively discourages learning it at this point if you're not intimately familiar with "deeper" programming.
    Sorry for the rant.
     
    NotaNaN and MostHated like this.
  3. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    That's because Unity has chosen to share the technology with the public at a fairly early stage. It's great for unity because they get a lot of feedback. It's great for us users because Unity gets a lot of feedback (which hopefully translates to improvements) and we get our hands on it to satisfy our curiosity. As with any early tech, it's going to take a while until sufficient examples, tutorials and community knowledge/experience has accumulated to make it easy for less experienced people to jump in. That's simply the way things work.

    Don't get me wrong, threads like this are great for fostering/spreading knowledge so far. But a lot of the answers you'll get will only represent the current, kinda volatile state of things because a) not all features are there yet (e. g. first-class editor support for pure ECS) b) some features may change and c) people haven't had too much time yet to put the systems to a test in the field.
     
    Lurking-Ninja and MostHated like this.
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    But please do share any ECS code and why it might stop you as we all need/learn from it including Unity :)
     
    MadeFromPolygons and one_one like this.
  5. one_one

    one_one

    Joined:
    May 20, 2013
    Posts:
    621
    Absolutely! What I meant to say was that the current state discussed here shouldn't necessarily be used for long-term production or feature planning, or deciding whether ECS might be worthwhile to learn or not.
     
  6. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Well I'm aware that everything is up for change at this point, I know most of my rant will be resolved over time as ECS will go gold, my issue mostly stands in being utterly lost right now with everything being outdated and scattered about. The only place Unity has everything put together for a quick overview is the Introduction to ECS pages in the tutorials section which as I mentioned before are outdated.
    I understand it's difficult (edit: impractical and a waste of effort) to make a new video for each and every update, but just a few text pages that undergo regular (bi-weekly maybe?) maintenance to stay accurate would be already such a massive step forward.
    Video tutorials at this stage were a bad idea to begin with in my opinion, a feeling that isn't exactly helped by the fact that the intro video is made by Brackeys who, despite being associated with Unity, is not a Unity dev or employee. Kindof gives off a "we scrabbled this tutorial series together from what we could find" vibe.
    Once you've put something in the tutorials section, most regular users tend to assume it is at least workable and the info in there will compile, a trap I myself just fell into in the case of ECS.

    As for deciding whether it's worth it at all to learn ECS, I was convinced when they mentioned mobile games would consume less battery, combined with the sheer scale of things like the Nordeus demo. It makes it doubly frustrating when you want to put your spare time to learning this awesome new thing only to see the learning resources might as well not exist. Add to that the relative vagueness of where this whole system is going to go and when it will be gold (I remember it being said 2019.1 but the current roadmap has another feature for the jobsystem planned in 2019, soooo... it won't be?), as well as what the current status is, and well... I'm quite disappointed.
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Video tutorials are an actual complete and pointless waste of time for things that only exist in text format. Serious waste of time.

    Documentation should be used.
     
    Silly_Rollo likes this.
  8. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    1. You must copy data to the job or prepare the data in the new native container data type. You can receive the computation result via the native container. You cannot use reference type in a job. You cannot use static in a job.
    2. You don't have to copy data to the job if you want to compute on the data that are attached on entities. With ComponentDataArray the job can make changes to the data directly.
    3. A job that has completed its calculation cannot interact with any of existing Unity API directly since they are not thread safe, the bridge are native containers. The only exception is the Transform via TransformAccessArray.
    4. Cannot put a bool and other non-blittable type in the component data.
    5. If your Job code works it does not mean it will be 100% burst compilable.
    6. Cannot move only some entities to an other world, can only move all entities from an other world.
    7. Cannot serialize only some entities, you must serialize the whole world. The serialization is not backward compatible and no tools for conflict resolution yet. (renamed fields, etc)
    8. Cannot put 2 of the same type of component data on 1 entity.
    9. The classic drawing code Graphics.DrawMesh etc. cannot accept native container as a data so if your job aims to draw something with computed data, you have to take time copying those data out.
     
    Last edited: Sep 17, 2018
    AshwinMods, friflo, Flurgle and 4 others like this.
  9. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I wouldn't completely say that since there's plenty of cases where people write/copy the code and then get confused as to "where they need to put it" or "how to use it" etc etc. I'd definitely push for making sure all code written in the video tutorials has it posted under the page (Unity generally does this, but there's some pages that don't have code attached), but a short extra video is not too bad assuming the topic is stable enough to warrant the effort. But yes, I definitely wouldn't mind written tutorials for experimental features. Easier to maintain and update without too much hassle, maybe throw in a screenshot or two.
     
    one_one likes this.
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    This is ECS... it's not a beginner subject and changes to videos do seem somewhat more convoluted.
     
    one_one likes this.
  11. Defiant_Games

    Defiant_Games

    Joined:
    Jul 18, 2012
    Posts:
    6
    Don't want to deviate off topic but I disagree. Even when they get a little out dated they can be a way to get started for many. They may not work well for you, but people learn in different ways and such a blanket statement deserves to be refuted.
     
    NotaNaN and Antypodish like this.
  12. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Yes it may be true, if executed incorrectly.

    For example, when I was starting with ECS, first thing I looked into videos, to get idea how things works. Then looked into samples. Tried replicated bits of video and play with samples, while slowly emerging into documentation. There is lot of thing in docs, which may be overwhelming at start. And of course lots of stuff missing as well.

    Agree, hence different sources and ways of passing information is needed.

    And to validate my point, look simply on existing ECS videos and you can judge how pointless / useful they are, when looking into popularity rate.

    upload_2018-9-18_18-22-57.png

    However, after some time of using ECS, I pretty much focus on docs and forum, while didn't looked into potential video solutions. Maybe they are, or not. But either way, quickly become outdated, at current ECS state. Yet doesn't means, they are useless.
     
    Last edited: Sep 18, 2018
  13. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    OK.

    If you think making videos is so useful for something that is changing on a daily basis, cool. I think it would be nice to have some written docs because those can change daily too, unlike time consuming videos.

    Of course when ECS is done someday there will be many videos that won't need to be deleted from youtube on account of being utterly outdated and broken.

    For now, I would like some text docs because those can change quickly, and be updated easily.
     
    NotaNaN and MostHated like this.
  14. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Sure.

    Yet, until user contribution to docs will be permitted, we relay on devs good will and their time, to update it.
    I remember somewhere (in? EntityComponentSystemSamples/Documentation/index.md) has been mentioned, that for now, until ECS solid ground is established, no user direct contribution will be accepted. I think this referencing to ECS docs and source code repositories on github.

    Until then, our best most actual source is forum, and source code.

    Regarding outdated videos, unfortunately already happening.

    For example depreciated FixedArray
     
  15. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah and without reliable subtitles, Unity simply alienates people with disabilities or who may have competent reading skill but not understand spoken in other languages.
     
  16. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Do you mind elaborate what you mean exactly by
    Asking, since this video has subtitles
    upload_2018-9-18_19-39-1.png
     
  17. angusmf

    angusmf

    Joined:
    Jan 19, 2015
    Posts:
    261
    Coming Soon to the Asset Store - U-Procedural U-Tutorial U-Video U-Generator Pro (Free Edition)!!!

    Just kidding.
     
    xVergilx and hippocoder like this.
  18. Kiragan-Games

    Kiragan-Games

    Joined:
    Jan 8, 2016
    Posts:
    20
    Is it possible to create character with child objects with root/animation etc using Pure ECS ?
     
  19. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,555
    You can use Attach component for child transform. Look it up in the TransformSystem section in the documentation.