Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ECS Pattern of AI Framework

Discussion in 'Entity Component System' started by cdm456852, Sep 13, 2020.

  1. cdm456852

    cdm456852

    Joined:
    Nov 21, 2017
    Posts:
    33
    Hi guys, I am writing a MOBA game using the dots framework, And now I am doing the AI part of the Hero, And I could not find some information about the AI Framework of Dots, Could you guys give me some information?
     
  2. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
  3. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    There is no AI framework for DOTS is the basic answer. You have to write your own.
     
    cdm456852 and Nyanpas like this.
  4. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    I don't see why you would want to do that. AI does not get any performance boost from DOTS. You can use any existing AI framework that fits your needs.
     
  5. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Disagree, burst can improve performance significantly - though it's painful to get it to work with traditional AI patterns.
     
    DotusX, charleshendry and davenirline like this.
  6. cdm456852

    cdm456852

    Joined:
    Nov 21, 2017
    Posts:
    33
    That is a true man, That is why I need a DOTS AI Framework to resolve the AI need of my game, Because my game was based on the DOTS, So I can not use the traditional AI solution.
     
    charleshendry likes this.
  7. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    I would disagree, I am working quite a lot with multiple AI frameworks at university and the thing is DOTS improves your performance on working on a lot of data through improving your cpu cache coherency, which is useless for AI in games as the data comes from the game frame by frame and not all at once, so you only work on a small part of data at the same time. Then AI is mostly bottle necked by the speed you can do calculations at, which is why special AI chips were developed and most AI frameworks run on a GPU.

    Burst does improve performance especially with SIMD and FP calculations on the cpu, but since most AI frameworks don't use the cpu this has no effect.

    If you trained an AI and you just want it to control your in game enemies, then in that case I would agree that there is a case for running this on the CPU as this will make sure it runs on all platforms, even though it will be slower.
     
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,877
    https://forum.unity.com/threads/ai-in-ecs-what-approaches-do-we-have.672310/

    Ive helped write and/or improve a few enterprise in-house AI frameworks at the places I have worked, and nothing I have experienced leads me to agree that it could not benefit. Certainly not an authority on the subject (and dont claim to be) but I have enough hands on experience to know that there definately are multiple ways for AI systems to benefit from things that ECS, DOTs and SIMD offer.

    If your trying to compare existing AI frameworks and patterns then yes they will not all necessarily be a good fit, but thats the point. You have to make something that works well with ECS, which may not mean you can use every pattern you want to. But certainly there will be ways to develop AI that benefits greatly from everything ECS, DOTS and SIMD offer.

    That thread I linked from joachim is just one example of good discussion that has multiple posts that offer potential avenues to try in this regard. I would not make assumptions about new-ish technologies based solely on what you learn/experience at university :)
     
    DotusX, charleshendry and Nyanpas like this.
  9. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    ML != AI. ML is actually not a common tool for ai in real games. You have perfect intelligence for one thing. You don't have to try to beat the player that's easy and not really the goal. It's an experience/feel you are after and often very arbitrary decisions based on the feel of the game. Lots of arbitrary tuning in ways ML can't even handle. Or if it can you spend hours/days tweaking models to get to the same point simpler approaches would get you to in a few minutes.

    So in the context of actual games AI is really a HUGE surface area. Go lookup some GDC talks on AI. What actually stands out most about them is how varied the approaches are. Partly because there isn't one tool that works well for all games. So developers just pick what looks best and then make it work. IMO it's dubious if rigid AI frameworks actually provide significant value in most cases.

    Also even if you use ML I highly doubt you would be doing runtime training. Queries are going to be cheap, and just intermixed with other gamelogic which get good use out of burst.
     
    Nyanpas likes this.
  10. Nyanpas

    Nyanpas

    Joined:
    Dec 29, 2016
    Posts:
    406
    I will recommend this on AI in games:



    It is never about the system behind, it is what the player believes is the system behind.
     
    DotusX and MNNoxMortem like this.
  11. turick00

    turick00

    Joined:
    Jul 14, 2020
    Posts:
    31
    Someone might actually want the design aspect of ECS, scaling out systems horizontally and breaking the nightmare that is OOP inheritance hierarchies. Someone may also not want a pure solution and not a hybrid architecture. Someone might already have existing entities with component data that needs to be used as inputs to AI decisions, so it lends itself to a system. Someone might just want to hone their DOTS/ECS skills and knowledge.

    I dunno, I can think of lots of reasons why I would want to use DOTS/ECS for reasons other than strictly performance.
     
    Nyanpas likes this.
  12. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    DOTS is a great fit for Game AI solutions.

    We have examples of finite state machines, behavior trees, and other models working in ECS which perform significantly faster (at scale) than their OOP counterparts.

    But what we are most excited about are a few new models for game ai, which we wrote specifically for the strengths of ECS and Jobs. These aren’t FSMs or BTs, but they fill that same space as ways to organize and execute ai behavior. So far those are our fastest tools for game ai, and we have slowly been adapting our entire workflow to think in terms of these new models.

    like others have said, DOTS can give you so much speed over OOP code that it lets you lean more in a convenience direction if you want to. For example, we’ve made test projects in which nearly *everything* in a game (including player controls) is handled by the same ai behavior engine. It’s technically slower than it could be, but it’s so fast that performance is not a concern. And in these tests, we did notice a huge speed up - in iteration time. ;)

    Just wanted to chime in to say that - not only can DOTS work well for existing ai approaches, but it opens up space for new exciting options.
     
    Last edited: Sep 15, 2020
    DotusX, bb8_1, turick00 and 2 others like this.
  13. davenirline

    davenirline

    Joined:
    Jul 7, 2010
    Posts:
    943
    But there's no in depth guide yet on how to do this correctly.
     
  14. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    Very true. But to be fair, it’s also true for most DOTS topics, with the exception of Physics and (kind of) networking. Fingers crossed that Skinned animation makes it into that list this year. :D

    it’s still early days, and the ECS part of DOTS is still pretty deep in development. At this point, we have to figure most things out for ourselves, and the environment could change at any moment.
     
    Last edited: Sep 16, 2020
    DotusX likes this.
  15. Ashkan_gc

    Ashkan_gc

    Joined:
    Aug 12, 2009
    Posts:
    1,102
    @PublicEnumE any examples? Do you mean utility AI combined with influence maps?
     
    PublicEnumE likes this.
  16. PublicEnumE

    PublicEnumE

    Joined:
    Feb 3, 2019
    Posts:
    729
    No, and I’m sorry. :( there are contract reasons why we can’t share our work, which I always feel bad about.

    That’s part of why I rarely post in here - I hate bringing up things that I can’t really expand on. Maybe in the future.
     
    Last edited: Sep 16, 2020