Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

To ECS or not to ECS

Discussion in 'General Discussion' started by Reloque, Oct 28, 2019.

  1. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,525
    Oh I know, I mean C# is overall still OOP language. But the way you handle the data is much more cleaner I meant, and it makes sense as to why it would be more efficient just even looking at it.
     
  2. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    I do like the ECS bit so far. I do have a pretty solid background as developer, so it might not be representative of what most people feel. However, I do feel there is something to say against the complexity at some points. I mean, I don't want to reinvent the wheel constantly. How to render for example, should not be up to me. I make the game logic and some design, wether DrawMeshInstancedIndirect should be used or not, is for game makers often a far too low a level decision.

    I mean it works, but it does get in the way of rapid prototyping. UV's, meshes and rendering have never been my strong suit or interest. As far as I am concerned, that stuff should 'just work'. Game logic, AI and game mechanics, that's what I want to make. Implementing that in ECS seems fun and efficient. Getting the rendering to work is a hurdle, one I hope that is solved for me instead of by me.

    In effect, I struggled and frustrated to get a sprite to render in ECS. But, once I ate that frog, I moved on to implementing a way to have a few hundred asteroids be mined by a few dozen mining craft while a few thousand other objects zoom around, and that has been honest, undiluted fun to do.
     
    iamthwee likes this.
  3. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    True but a good game doesn't equate to thousands of more objects or bullets IMO.
     
  4. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    We are working on advanced bots, for example good "vision" is important. Little video on our bots,



    If you have many active AI agents and do this on the render thread you could start to see impact on rendering. We are movign this to ESC and C# Job system
     
    tonialatalo and iamthwee like this.
  5. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    It certainly doesn't. In this particular instance, there are mining boats homing in on asteroids, bringing in materials to a base ship. There are several dozen boats, several hundreds of asteroids and the full game world contains a few thousand other entities. And that's before lasers, bullets, particles and such come in. Those facts in itself don't make the game good or bad I believe.
     
    GameDevCouple_I likes this.
  6. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Just remember that its in pre-alpha, its not that you will be expected to do that stuff manually, its that your effectively getting eyes on months and months before it will even go into "preview".

    I agree its painful handling rendering for now, but as far as prealpha software goes its still really good overall.

    They have already said rendering, physics etc will be there when it releases.
     
    Kiwasi, angrypenguin and Reloque like this.
  7. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    I know. I knew what I was getting into in regards to stability et all.
     
    GameDevCouple_I likes this.
  8. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    You sound mostly like your in the same boat as me. I have been writing an underwater ecoystem simulation, and getting the flocking of fish and their AI to work in ECS has been a dream. getting the fish to draw has been a nightmare :D
     
    tonialatalo and Reloque like this.
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,529
    I beg to differ. There are lots of game designs that rely on thousands of objects to be fun. Crafting games like MineCraft or Factorio wouldn't work if your world only had a hundred blocks. Grand strategy games tend to do better with thousands of objects around. Your average RTS does better if you can render thousands of bullets individually.

    Sure, there are plenty of game designs where there is no benefit from simply adding more objects. But many games do better with more.
     
    Ryiah likes this.
  10. Murgilod

    Murgilod

    Joined:
    Nov 12, 2013
    Posts:
    6,179
    Also it's not like handling that amount of data at a time is limited to just object implementation. I can think of a lot of uses for ECS and jobs to integrate in really interesting ways for things like extremely robust meshing operations.
     
    Kiwasi and Ryiah like this.
  11. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    True, some people just love crafting and shooting up tonnes of crap, ain't for me though, give me a thoughtful point and click game with a good art-style and interesting narrative any day of the week.

    Fran Bow is still <3
     
  12. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    Well, I am well underway, but thought I'd ask here before just opening a new thread; Colliders and RigidBodies, those are not converted using IConvertGameObjectToEntity yet are they? Before I go off on a heedless search.

    -Edit: does work kinda with Unity.Physics I see.
     
    Last edited: Nov 7, 2019
  13. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,437
    DOTS is mostly about making Unity competitive where it hasn't been. Which is with modern higher end 3D games. In that context the complexity you bemoan is not optional. And in fact DOTS greatly simplifies the necessary complexity there compared to how other engines handle it. Which is mostly C++ without any standardized approach.

    It's the industry that is setting the bar. Unity is simply moving to keep up. Simple games aren't really simple anymore, even mobile is now far more complex then it ever was.
     
  14. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    Complex games need abstraction. Doing an entire complex game domain through low level apis like DrawMeshInstancedIndirect will get unmaintainable fast.
     
  15. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,166
    Is anyone arguing against that? I think the thing is that the best abstraction for my game may well be different to the best abstraction for your game.

    That said, I think the issue here is just that it's not finished yet, so people are having to fill gaps themselves. I think it's good that we can do that, because it means if I can think of a better approach to a specific use case I can implement it, but I can also use the provided ones where they're good enough. Best of both worlds. :)
     
  16. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    Well it did sound a bit like that on snack time. And dokt get me wrong, there are times you need that fine graded control over rendering. But if you went and renderers every single thing with that method it would become a mess quick.

    It would be like designing UI from code instead of some kind of designer or view markup language. (I have seen this, it ain't pretty)
     
  17. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,166
    In the specific context of "making Unity competitive ... with modern higher end 3D games" I think @snacktime's statement is spot on, though.

    Check out the credits screen of most modern "AAA" titles. They can afford to sit one or more veterans down for weeks or months to implement a single part of their game. The results of that are what Unity is trying to provide tools to compete with.

    That doesn't mean everyone needs to use that complexity themselves all the time, so having a bunch of out-of-the-box implementations for common use cases is great, and will suit most people for most things. But in the comparatively rare cases where you need something use-case specific... the complexity is (probably) necessary.
     
    MrArcher likes this.
  18. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    The complexity that I bemoan, is the bit that I don't want to get into as game designer. Sure, in a big project, you'd have people responsible for all sorts of tasks. But, having to go that deep into the engine for common, if complex tasks, should not be needed. If I put a sprite on there, it should render. Figuring out how to render it should be the tools job, not mine. Just because I can, doesn't mean that it's a productive use of time. I mean, there are tons of people out there that can to it a lot better then me, but only I can design/make "my" game if you get my meaning.

    Just like I write in C# and Python and R and not in assembler even though I could do that, I use Unity because of ease of prototyping and game logic. To misquote a common saying; "optimisation is the compilers job".
     
    Last edited: Nov 8, 2019
  19. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    2,437

    If you use features that are supported then as a designer the flow is really the same pretty much. You create gameobjects add components along with a convert to entity component and it just works.

    Sprites aren't supported right now. I assumed you were aware of that and were trying to implement them yourself, which at this point would be a bit complex.
     
    Kiwasi and Reloque like this.
  20. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    Yup. I knew about the sprites. Or at least knew soon enough that I could've gone another way. But, after doing that bit, I really love my swarm of mining boats and asteroids. Although still struggling to let go of the OO mindset.

    For instance, in MB I would've added one script that does this kinda of thing to each mining boat;
    • Find nearest asteroid
    • Turn toward nearest asteroid
    • Fly forward
    • If asteroid is in range, mine
    Now, I have to split that up in a more DO style, so that's a learning right there. But considering it as being a database with queries as a mindset works. Kinda like

    "From world select * were moveable = true" and then work from there. Harder to put into words than I thought.
     
    tonialatalo likes this.
  21. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Same with my fish. On the flipside, now that I have a:

    - Move towards a point system
    - Turn towards a point system

    I will never have to write them again unless I need moving towards something to work a completely different way. And even then, piping in different values should facilitate that if I wrote it correctly.

    Its difficult at the moment for me to break things down so granular after years of MB but bit by bit I am seeing that its allowing me to move towards a "dont reinvent the wheel" principle, but on a whole other level :D

    Ultimately other than performance I think thats where I will really reap the most rewards of ECS, when I move onto my next project and find that I can take a bunch of this granular stuff and use it as is therefore saving me lots of time and allowing me to build a much more generic library of capabilities to use in each application than previously was possible with minimal effort
     
    pcg, tonialatalo and Lurking-Ninja like this.
  22. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    This is call of duty fish AI all over again :)
     
    tonialatalo likes this.
  23. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    One thing that does still kinda of makes me wonder, how does one do a thing like "select all asteroids" but not "all mining ships". Right now, I use tags, like the video suggested, but that doesn't seem like the proper way to do that.
     
  24. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,166
    There are a few ways.

    A simple way would be to do FindObjectsOfType<DesiredType>(). This will give you an array of all active DesiredType components, from which you can access their GameObjects if needed. However, it's pretty slow as it traverses the whole scene looking for components of the desired type, so it's not something you want to do each frame. Also, as far as I'm aware this doesn't find inactive stuff.

    Personally, if I know I need to look up a particular set of objects, I just have my code track that set of objects in the first place. For instance, each DesiredType might add itself to a collection in Awake() and remove itself from that collection in OnDestroy() (or that could be done in OnEnable() and OnDisable(), depending on your needs). Then you can access them all without traversing the scene at all. And you can pick whatever collection type is optimal for your usage pattern.

    Remember, even thought this is "scripting" within a game engine, you still have a full C# / .NET runtime at your disposal, and with a few exceptions can do anything you could do in a normal C# application. The main catches are a) some platforms have some restrictions, and b) don't anger the Garbage Collector at inappropriate times.
     
    Socrates likes this.
  25. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    Garbage collection....good lord, that is some flashback right there.

    But, yeah, it's a learning process. The mining ships are smart, the asteroids are not. I don't know how 'DOTS-appropiate' it would be the write a system that is just 'Find Nearest Mineable Object'

    And to go like this;
    • Select all entities with the type "Miner"
    • Find nearest mineable object
    • Set that object as target
    And have another to;
    • Turn towards targets
    And yet another to;
    • Increase velocity
     
  26. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Lol, Not everyone is making a first person shooter mate.

    I think your making a vast jump from 1 comment, to assuming you even know what my game is about. No, its not 'call of duty fish AI all over again' because my game is nothing like call of duty, and within my project wildlife are not a small part of the game but an integral part and a core pillar of design - hence why they are being given in depth development time and a deep featureset.

    In general its probably good practise to not make assumption based comments on other peoples projects if you know nothing about them :)

    Yeah that would be dots appropriate :) You could use a 4th system though that would be "find distance to X" system, so that the distance checking is generic and usable by other stuff too, and then use distance returned by that inside of your find distance to nearest miner system to get target; but yeah it sounds DOTS appropriate
     
    Last edited: Nov 11, 2019
  27. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    Somebody needs to drink less coffee :p
     
  28. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Nah, you just need to have more manners with your posting.
     
  29. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    This all sounds a bit fishy to me :D
     
    GameDevCouple_I likes this.
  30. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Thats a pun I can get behind :D

    EDIT: bugger, missed a chance for more fish related puns but its deadline day and my brain isnt working fast enough
     
    iamthwee likes this.
  31. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    Aw come on spill the beans, is it an isometric fishing game? Is everyone behind some sort of NDA except Anders I want to see screenshots now, and hopefully schools of fish moving in perfect unison!
     
    GameDevCouple_I likes this.
  32. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    Yes, our team is behind an NDA-like agreement and likely to stay that way until release plan is finalised with publishers, but I promise Ill be back with dev logs and such around then!

    EDIT: probably best to clarify its not an actual NDA per-se, but a formal agreement between ourselves and publisher that means we cannot post any publically viewable information about certain things related to the game, which tends to be almost anything to do with the game including name, logo, screenshots, etc etc. We had a website up which has been taken offline until after this period lapses, after which it will be the best source of info. And no I cant post a link to that yet either XD
     
    iamthwee likes this.
  33. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    OK good luck man, knuckle down and get the hell off unity forums! It's a time sink!
     
    GameDevCouple_I likes this.
  34. GameDevCouple_I

    GameDevCouple_I

    Joined:
    Oct 5, 2013
    Posts:
    2,137
    These are true words if there ever were any!

    Unfortunately I am building this on the side of my day job so I am at work at the moment, but hopefully will be able to quit that once things are settled! (I cant wait for my only job all day to be working on my teams project instead of split between 2 teams and 2 offices)
     
  35. iamthwee

    iamthwee

    Joined:
    Nov 27, 2015
    Posts:
    1,950
    Well Anders once told us it is important to have a good friends and family network that supports your game dev goals.

    For example, when Anders is working typically his wife looks after the kids.

    Wife: Anders can you look after the kids today or are you working on your game?
    Anders: Sorry honey, I'm lightmapping, it's gonna take 8hrs and involves my full concentration :D
     
  36. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,166
    Do you need to select all entities of type Miner? Last time I did something like this I used a data structure designed for spatial lookup - something like a Quad Tree. However, that wasn't using DOTS, so it may not be a good solution there.
     
  37. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    With the classic framework culling group API are a fast way of testing for nearability (Its basically a built in Quad tree lookup)
     
    angrypenguin likes this.
  38. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184
    Well, yes, I need all the miner entities to check what the nearest rock is. They are independent mining boats. Their 'captain' is to decide on what rock to mine based on a whole set of carefully weighed and measure metrics that.....okay, who am I kidding? The captains is a lazy bastard that wants to fly to the nearest rock to mine because it's easy.

    In all seriousness, every boat needs make decisions, right now, that comes down to what asteroid is nearest and go there. So yeah, every boat makes that call, I really see no other way to "simulate" the captain of that boat making a call, other than per boat.
     
  39. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,214
    I draw parallels to the Miners/Minors joke in the cult classic Galaxy Quest

     
  40. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    6,243
    Yep you need some spatial mapping as @angrypenguin stated. Weather is 3D or 2D. Could be quadtree, octree or other.
    I use own custom system, which basically chunkify the 3d space, to search near life instances.
    https://forum.unity.com/posts/5161949/
    Works very well in DOTS :)
     
    iamthwee likes this.
  41. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    12,166
    My mistake, I misread your notes. I interpreted it as finding all Miners to see which one of them was closest, but that's not what you're doing.

    I would assume that the "Find nearest mineable..." would do the kind of thing I was talking about.
     
  42. Reloque

    Reloque

    Joined:
    Apr 28, 2015
    Posts:
    184