Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Utility AI (Discussion)

Discussion in 'Game Design' started by Antypodish, Jan 4, 2019.

  1. Antypodish


    Apr 29, 2014
    First there is article on Gamasutra for reference.
    Are Behavior Trees a Thing of the Past? - Gamasutra
    I think title is more than click bite, but content is good n my opinion.

    I am planning to implement Utility AI based on weights, using ECS. But not making (at least at this point) any visual editor.

    Just as from article example.

    I have general concept how to approach it in terms of coding.
    But here I am not asking about the specific algorithms. Rather doing more research in the topic.
    While there is plenty to read and resources available on the net, that I can refer to, I would like simply ask, if you have any good additional references in your opinion, which may be worth to share and read.

    However, if you have better alternative to Utility AI, or own point of view, please share as well.

    Many thx in advance.
    Lurking-Ninja likes this.
  2. Braineeee


    Nov 9, 2014
    Check out AI For Game Developers by David M Bourg (and another guy I'm too lazy to recall right now). Its got some good introductory stuff to things like Fuzzy Logic, pathfinding, and stuff. It was an easy read.
    Antypodish likes this.
  3. Antypodish


    Apr 29, 2014
    Thx, I found his book on a multiple stores / websites.

    AI for Game Developers
    Creating Intelligent Behavior in Games
    by David M Bourg, Glenn Seemann

    Very last sentence says, what you just mentioned indeed.
  4. Lurking-Ninja


    Jan 20, 2015
    For a working reference (obviously it has been written OOP):

    Mostly the same or similar like Jakob's article, but maybe contain some extras:

    I like the Utility AI-approach, although it's very hard to do it good by a one-man-show like me. Mainly because of the separation of design and behavior. So either you hire a lot of Q&A, DIY Q&A a lot or risk that unwanted emergent behavior will creep up in the application.
    Obviously it's mainly because of the added complexity and abstraction. When you make a BT-approach it's more clear when your agent will do what (usually). In exchange Utility can have very fun emergent behavior. But it's a nightmare to test. On the other hand I have very limited experience since the one-man-show thing, obviously. So I may be doing it wrong.
    Last edited: Jan 4, 2019
  5. Antypodish


    Apr 29, 2014
    Both links are very nice readings.
    Second one has more like reinforced few of my concept, adding extra, regarding more type of curves.
    Regarding first article, this is something I will come back and read again through. There are few keywords listed, of some I want to get more familiar with.

    Yep, this is some of my potential concerns. But way I may try to approach it, is by limiting, of how many utilities graphs I can plot, to evaluate score at once. Then maybe create I create sub system with another Utility AI. Just kind of like Behaviour Tree leafs work. That would be kind of hybrid approach.
    However, this concept is not yet decided.

    While I like this concept generally, and I may implement it as well at some point, I am not convinced yet regarding expand-ability, in case of my moddable game. On other hand Utility-AI can indeed creep out strange behaviors, if untested graph is being added ;) But BT feels to me more strict. This is my main reason, to hold me back against it atm, toward U-AI.

    This is what I am aiming for. Even for the cost of testing disadvantage. In worse case scenario, I will be back to BT.

    Definitely for limited time and knowledge, we can do only so much, in certain time span.
    I did investigated BTs and U-AI last year already. And multiple sources I looked into, also indicated concerns and points, you just have raised.
    Lurking-Ninja likes this.
  6. SparrowsNest


    Apr 6, 2017
    Lurking-Ninja and Antypodish like this.
  7. Antypodish


    Apr 29, 2014
    This is cool. Over 800 pages to enjoy reading ;)

    What I found interesting so far, is task time factor ( page 408) and "smell" concept at page 425.
    Of course smell can be interpreted as distance to the target, or cover, to decide weather shoot, or hide.

    Included good references to games. For example sims.

    Overall I like it. Many thanks.
  8. Antypodish


    Apr 29, 2014
    Just got a thought, which I would leave it here, so I don't forget.

    Since I am focusing on modding aspect to implement Utility AI, I am consider develop spreadsheet as design stage, which will match relevant utility and behaviour. Then generate output data, in form of fields, or maybe Json, containing trend line functions, ready for import to Unity, where algorithms will take care for the rest and execution.
  9. dibdab


    Jul 5, 2011
    this was a real eye-opener. so utility-ai is a decision engine based on the evaluation of animation curves.

    made a prototype.
    first a script that creates curves and adds keyframes to it in runtime
    if want to add a new value on a time that has already a keyframe it's overwritten with the new value
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. public class AnimCurveExample : MonoBehaviour {
    9.     public AnimationCurve curve;
    11.     public KeyCode addK = KeyCode.Keypad0;
    12.     [Range(0.0f, 1.0f)] public float time;
    13.     [Range(-1.0f, 1.0f)] public float value;
    15.     public int maxKeyFrames = 10;
    17.     Keyframe[] ks;
    18.     [HideInInspector] public int i = 1;//for new key 1-9
    19.     int x;
    20.     bool removed;
    22.     void Start()
    23.     {
    24.             ks = new Keyframe[maxKeyFrames];
    26.             curve = new AnimationCurve (new Keyframe (0, 0), new Keyframe (1, 1));
    27.             curve.preWrapMode = WrapMode.Once;
    28.             curve.postWrapMode = WrapMode.Once;
    29.     }
    32.     void Update()
    33.     {
    34.         if (Input.GetKeyDown (addK)) {
    36.             removed = false;
    37.             for (x = 0; x < ks.Length; x++) {
    39.                 if (ks[x].time == time) {
    40.                     curve.RemoveKey (x);
    41.                     ks [x] = new Keyframe (time, value);
    42.                     curve.AddKey (ks [x]);
    43.                     removed = true;
    44.                     print("key removed " + x);
    45.                     return;
    46.                 }
    47.             }
    49.             if (!removed && i<ks.Length-1) {
    50.                 ks [i] = new Keyframe (time, value);
    51.                 curve.AddKey (ks [i]);
    52.                 print("key added " + i);
    53.                 i += 1;
    54.             }
    55.         }
    56.     }
    59. }
    and here's a curves-evaluator example
    drag timeExample variable to see highest

    Attached Files:

    Antypodish likes this.
  10. Antypodish


    Apr 29, 2014
    This is simple and neat.
    Many thanks for sharing.

    I am glad that topic become useful otherwise.
  11. Gladyon


    Sep 10, 2015
    I was planning to use behaviour trees at first, but they are so predictable that I've been looking into GOAP (Goal Oriented Action Planning), which is very similar, but for the player it's harder to predict the behaviour (which in the end is very important, because if the player can predict all the AI actions, that remove some of the fun).

    I haven't (yet) looked in depth into the Utility AI, but it seems to me that it may be quite hard to balance for complex systems.
    Each time you change a 'weight' in order to make the AI favor one choice in one case because it's the obvious course of action, you take the risk of degrading other decisions the AI may take.
    That's the main reason I was interested in Behaviour Trees in the first place, it seems that they can stay manageable even in large and complex systems.

    To be honest, I think there's no golden solution for the AI.
    I think that the most efficient way to approach AI in a game (if you need some complex one), is to use several tools.
    I really doubt that one tool can fit for all situations, so in the end I guess I'll end up with 4-5 different AI tools, maybe more.

    For example, Behaviour Trees are perfect to handle reflex behaviours, they are predictable anyway so that's not a problem, and Behaviour Trees are usually quite fast to compute and easy to configure/maintain.
    And if you need some more complex behaviours, then Utility AI seem to be more interesting (even if it may be quite hard to balance/maintain).
    And probably that none of these algorithm can be used if you need some learning feature in some part of the game, except maybe if you use a neural network to generate some inputs for the Utility AI, which would make it even harder to balance, but may provide some interesting results.
  12. Antypodish


    Apr 29, 2014
    Utility AI is interesting concept. There is quite to read about it, as well as any other AIs.
    It can be true, that weighting may introduce some balance difficulties. I have not fully designed solution as of yet, but thinking of ensuring of smaller Utility AIs controlling other Utilit AI / brains, or even behavior trees for smaller / obvious tasks. However, Utility AI can be also acting as simple switch just like BT. So one tool may potentially do multiple solutions.

    For additional unpredictability, fuzziness may be added if needed.

    You can have any type of IA to drive machine learning and vice versa. Question is, weather is needed, or is worth it. Is even harder to maintain, since you need retrain, if anything related is changing. I love Neural Networks, and I got use of it in my main project. But will not be my main brain driver, even I though about it a lot before. Rather I will use for controllers.
  13. SparrowsNest


    Apr 6, 2017
    Not always, sometimes you need the player to know exactly how the AI works.(not in technical terms, but what effects what).
    In the game I'm working on right now you have an arena where you send you team of tank-bots to fight other teams, you get to setup the AI and you NEED to know what he will do with minimal trial & error, a good example for this with out writing a speech about my game is "Gratuitous Space Battles".
    Antypodish likes this.