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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

When will Unity get some real AI Solutions?

Discussion in 'General Discussion' started by Slyder, May 23, 2015.

  1. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    Nearly every game requires some level of AI and yet Unity still does not offer adequate solutions for building and managing serious AI structures. I'm talking about Behavior Trees.

    I have tried most of the 3rd party solutions for this and they are FAR too invasive and bloated. None of them seem to be seamlessly integrated with Unity. They feel like an unnecessarily complex glue on.

    For anyone who has tried UE4's Behavior Trees, you will know what I mean. The UE4 BT system is a fairly intuitive, barebones system that is highly modifiable and extensible. I write a class. It pops up in my Behavior Tree for use.

    Outside of building one myself, I don't see how I can get what I want in Unity and unfortunately, building one myself would take longer than moving back over to UE4 and re-climbing that mountain.


    I would like to get back into Unity so do I have any decent options here?
     
    Gekigengar likes this.
  2. TechiTech

    TechiTech

    Joined:
    Dec 13, 2014
    Posts:
    212
    which solutions have you tried in asset store?
     
  3. der_r

    der_r

    Joined:
    Mar 30, 2014
    Posts:
    259
    Behave 2 is far from bloated. I highly recommend it.
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,141
  5. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    Rain is overly complex. I don't want waypoints. I don't want "Brains". I don't want sensors...I don't want 3rd party NavMesh generation and pathfinding.

    I want the base functionality: The base node types that can be extended for custom behaviors. (Sequencers, Selectors, Tasks, etc...)
    I want the visual scripting: Building a full behavior tree in code would be a pain in the ass. The visual scripting properly manages this.
    I want the solution to function with the same Unity workflow: I can't even click and drag "target" objects into the Rain variables. They expect me to use their waypoint system.

    I want everything to attach neatly to gameobjects using standard Unity workflow.

    The base code for a Behavior tree is extremely simple. You can find full implementations online for free. The problem is the visual side of it. I'd say I'm fairly weak in the Unity editor extending area... The visual editor must know how to build the script that drives an AI Agent, which I can then attach directly to a game object, and I have absolutely no idea how this is done.
     
    Last edited: May 24, 2015
  6. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,141
    opsive likes this.
  7. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    Yeah, AI is insanely complex. I'm just not looking for a Full AI solution. I'm simply looking for a base Behavior Tree implementation that can be built upon easily.

    I understand why the asset store solutions are full blown general AI solutions. They're designed to tackle as many AI scenarios as possible in order to appeal to the majority of the market.

    I've always felt like the whole bolt-on concept was a blessing and a curse for Unity. They leave out basic things because you can find a solution on the Asset store. Nearly every bolt-on I have used for Unity has been bloated with features because they want to stand out over competitor solutions.
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    As opposed to the engine itself being bloated?

    Every feature will be extraneous to some users. Unity had to pick a line somewhere.
     
    McMayhem, angrypenguin, Ryiah and 2 others like this.
  9. 00christian00

    00christian00

    Joined:
    Jul 22, 2012
    Posts:
    1,033
    What's wrong with Unity state machine?
    You can build a pretty complex AI with that and it's visual like you want.
     
    der_r and Kiwasi like this.
  10. MysterySoftware

    MysterySoftware

    Joined:
    Sep 18, 2014
    Posts:
    46
    Hey guys,

    I've recently been working on a custom AI solution for Unity as the ones found in the Asset Store haven't really been able to convince me of their usefulness. The ones I've tried so far were either overly complex or way too simple.

    So I started coding a very simple behavior tree solution which uses the hierarchy window as a visual editor and a custom blackboard class.

    Here's a tiny bit of my behavior tree code.. I hope you might find it somewhat useful :)

    Edit: And a small example of how to implement the code…

    Code (CSharp):
    1. using UnityEngine;
    2. using BehaviorTrees;
    3. using Utilities;
    4.  
    5.  
    6. public class Agent : Blackboard {
    7.     public Task behaviorTree;
    8.  
    9.     public void Awake () {
    10.         if (behaviorTree == null)
    11.             Debug.LogWarning (name + ": No Behavior Tree!");
    12.  
    13.         NavMeshAgent nav = GetComponent<NavMeshAgent> ();
    14.  
    15.         if (nav != null)
    16.             AddPersistentEntry ("NavMeshAgent", new UnitySerializableType (nav));
    17.  
    18.         AudioSource aud = GetComponent<AudioSource> ();
    19.  
    20.         if (aud != null)
    21.             AddPersistentEntry ("AudioSource", new UnitySerializableType (aud));
    22.  
    23.         Initialize ();
    24.     }
    25.  
    26.     public void Start () {
    27.         if (behaviorTree != null)
    28.             behaviorTree.ResetTask (this);
    29.     }
    30.  
    31.     public void Update () {
    32.         if (behaviorTree != null) {
    33.             if (behaviorTree.GetState () == Task.State.Waiting) {
    34.                 behaviorTree.StartTask (this);
    35.             }
    36.  
    37.             if (behaviorTree.GetState () == Task.State.Running) {
    38.                 behaviorTree.ExecuteTask (this);
    39.             }
    40.         }
    41.     }
    42. }
     

    Attached Files:

    Last edited: May 25, 2015
  11. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    Thanks for this. I've been working on my own implementation as well and have ended up with something similar to yours. It'll be interesting to see another implemenation. I'll show mine once I have something more complete.
     
    MysterySoftware likes this.
  12. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I had a quick play with this. While it seems powerful enough the workflow is different enough from how Unity normally works to put me off. And the documentation/tutorials were weak.

    I might come back to it one day. But for now I'll simply code my own AI solutions.
     
  13. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,141
    Yes, the sole tutorial I watched made it seem a bit different from Unity. The main reason I link it to people is that it is free and they may as well evaluate it to see if they can use it or not.
     
    Kiwasi likes this.
  14. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    It is definitely a powerful tool. And nothing is ever lost by trying a free tool. If I was building complex FPS games it would probably get a longer look in.
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    @Slyder - Have you tried Behavior Designer which @Ryiah linked to? It holds up to your three requirements and is just a behavior tree tool. Of course, I am always interested in hearing suggestions on what can be improved.
     
  16. LaneFox

    LaneFox

    Joined:
    Jun 29, 2011
    Posts:
    7,384
    There are a number of free Behavior Tree systems available online, some in C++ but theres some C# solutions and I've found some unity specific ones on git... Documentation is quite slim though... So I think you're better off just rolling your own if you require something specific. But then, if you don't have time to study and develop your own bulletproof system that you can confidently rely on and scale up with a project than I would highly suggest just getting one off the Asset Store and learning it. That will be faster, cheaper in the long run, and yield better results.

    Although, you could just drop both of those suggestions and use a different method of making your AI. BT's aren't required in any way, just another means to an end.
     
  17. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,516
    Unfortunately everyone is looking for something different. There's no one thing Unity could build in that would suit everyone's needs.
     
    Kiwasi likes this.
  18. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    I have not gotten to the point of dropping money on an asset for AI yet. However, if I do, it will probably be Behavior Designer :)

    From the looks of it and the comments, it might be exactly what I'm looking for.
     
    opsive likes this.
  19. WJ

    WJ

    Joined:
    Oct 25, 2012
    Posts:
    97
    How is this :)

    The FSM & Behaviour tree are working just fine however I'm been adding lots of actions / Inventory System / Audio Management / Zone system using any shapes you like, you can draw them in the editor and trigger things like audio, events etc, and an RPG add on for managing actors / leveling / stats / formulas etc.

    I probably will separate the FSM and Behaviour tree and remove all the actions and sell them as one package as a core engine you can use and build your own scripts etc.

    At the moment it supports everything you specified, you write your scripts it picks them up automatically etc.

    Screen Shot 2015-05-26 at 17.19.26.png

    Screen Shot 2015-05-26 at 17.20.01.png

    It works and feels exactly like mecanim with snapping, styling etc.
     
    LiberLogic969 likes this.
  20. vee41

    vee41

    Joined:
    Nov 14, 2013
    Posts:
    32
    From solutions I've tested Behavior Designer stuck out, whole heartedly recommended! It focuses on being just a behavior tree solution and only that, and has enough depth to cover really complex use cases.
     
    opsive likes this.
  21. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Whaaaat? You also said in OP "I have tried most of the 3rd party solutions for this", so I am understandably confused. I know RAIN is free, but all the others I can think of are not (ICode, Behavior Designer, Behave, and many many more). That hardly sounds like "most".
     
    angrypenguin and Kiwasi like this.
  22. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Looks good! What plugin is that?
     
  23. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    I tried Rain, Skill (or something like that), and some other one I can't remember...

    There's Behave, Rain, Behavior Designer, and a couple others. There's not very many Behavior Tree solutions on the Asset store unless I missed some :p

    I only tried the free ones admittedly.
     
  24. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,533
    You get what you pay for. :) Behavior Designer is very good. It's a AAA tool, and the support is top notch.
     
    opsive likes this.
  25. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    Code (csharp):
    1.  
    2. class Blackboard : MonoBehaviour {
    3. //Store variables here
    4. }
    5.  
    6.  
    7. class BehaviorTree : MonoBehaviour {
    8. //Build BT in child of
    9. }
    10.  
    11.  
    12. //-------------------------------------------------------------------------------------------------------------------------
    13.  
    14.  
    15. class Node {
    16.  
    17.     public Blackboard vars;
    18.  
    19.     public StateEnum childState;
    20.  
    21.  
    22.     public Node(Blackboard bb){
    23.  
    24.         vars=bb;
    25.  
    26.     }
    27.  
    28. }
    29.  
    30.  
    31. //-------------------------------------------------------------------------------------------------------------------------
    32.  
    33.  
    34. class Root : Node {
    35.  
    36.     Node child;
    37.  
    38.  
    39.     public Root(Blackboard bb, Node node) : base(bb) {
    40.  
    41.         child=node;
    42.  
    43.     }
    44.  
    45. }
    46.  
    47. class Composite : Node {
    48.  
    49.     List<Node> children;
    50.  
    51.  
    52.     public Composite(Blackboard bb, parms Node[] nodes) : base(bb) {
    53.  
    54.         children=new List<Node>(nodes);
    55.  
    56.     }
    57.  
    58. }
    59.  
    60. class Task : Node {
    61.  
    62.     public StateEnum Tick(){
    63.  
    64.         //do some stuff return a State
    65.  
    66.     }
    67.  
    68.  
    69.     public Task(Blackboard bb) : base(bb){
    70.  
    71.     }
    72.  
    73. }
    74.  
    Very early and basic. missing things like protection at work lol...Won't work copy and pasted.

    But I should be able to build a tree through the constructor of Root() by generating a string based on a visual editor and then writing to a *.cs file....theoretically...

    I would build the Tree like:
    Code (csharp):
    1.  
    2.  
    3. Blackboard bb=GetComponent<Blackboard>();
    4.  
    5.  
    6. Root rt = new Root(bb, new Selector(bb, new Task(bb), new Sequence(bb, new Task(bb), new Task(bb))));
    7.  
    8.  
    This simple Tree "should" look like:
    BT.PNG
     
    Last edited: May 26, 2015
    MysterySoftware likes this.
  26. MysterySoftware

    MysterySoftware

    Joined:
    Sep 18, 2014
    Posts:
    46
    That's gonna be one hell of a constructor in a large BT :D
     
    Slyder likes this.
  27. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,555
    Ok. Don't forget NodeCanvas. It does BT, FSM and something else too. I have my eye on that one.
     
    Last edited: May 26, 2015
    _met44 likes this.
  28. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    haha yeah. Really it all depends on how I'm going to attach the Behavior Tree to the Game Object. Ideally it would be something standalone like Mecanim which would visually highlight the nodes that are running during a Tick.
     
  29. MysterySoftware

    MysterySoftware

    Joined:
    Sep 18, 2014
    Posts:
    46
    From what I understood, you want to create a C# file from the behavior tree you created in a visual editor, correct? Why go through all that trouble when you can build your BT in the hierarchy view. Your tasks being game objects as those will still be available during play time but can also be moved around in the editor and at runtime and do not have to be recompiled.

    Bildschirmfoto 2015-05-26 um 23.45.07.png

    The code I uploaded yesterday does exactly that. You're welcome to use it if you want :)
     
  30. Slyder

    Slyder

    Joined:
    Oct 17, 2013
    Posts:
    270
    That is probably the quickest solution available but since I am just fiddling around, I thought why not dive deep into it :D
     
    MysterySoftware likes this.
  31. WJ

    WJ

    Joined:
    Oct 25, 2012
    Posts:
    97
    It's one I've been working on for over a year now, I'll try to stick up a little video at some point today on what it has so far. I plan on releasing the FSM / BT / And full package as three separate pieces once it's ready. It's a complete replicate of Mecanim in it's behaviour, even down to debugging, and progress, snapping etc. Only difference is the left bar that saves you having to select the item in the project browser but that works too.
     
    Last edited: May 27, 2015
  32. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    I released a Behaviour Tree solution.
    Here is the main feature:

    - You define BTs by writing scripts in a simple language.
    - You define tasks as C# methods.
    - The execution of tree is visualized in realtime.

    Let me know what you guys think about it.

    More information here: http://www.pandabehaviour.com

    Edit:

    Here is a screen shot of the Panda Behaviour component with a BT script attached.
    This is a running tree. At a glance you can see which tasks is active ( highlighted line numbers), and what is the state of each task: running (blue), succeeded (green), failed (red), inactive (grey).

     
    Last edited: Mar 8, 2016
    Jamster likes this.
  33. JohnnyA

    JohnnyA

    Joined:
    Apr 9, 2010
    Posts:
    5,039
    @Slyder why do you care about the 'bloat'? A lot of that is editor stuff, the actual bloat probably has zero effect on your game (okay maybe few meg of IL).

    Or do you just mean that the bloat gets in the way of the user experience? You can't easily do what you want to do because the UI caters for too many options, etc.

    EDIT: Just realised this is a necro :s
     
  34. ericbegue

    ericbegue

    Joined:
    May 31, 2013
    Posts:
    1,353
    Oh, sorry. I should have warn I was posting on an old thread :p.