Search Unity

Behavior Designer - Behavior Trees for Everyone

Discussion in 'Assets and Asset Store' started by opsive, Feb 10, 2014.

  1. Hellwaiker

    Hellwaiker

    Joined:
    Jan 8, 2016
    Posts:
    118
    Hello, I'm using Movement Pack and WithinDistance code. And I want to use line of sight function.

    I'm having trouble understanding how it's supposed to work.

    In code on line 97 we have:
    Code (CSharp):
    1. if (lineOfSight.Value) {
    2.                         var hitTransform = MovementUtility.LineOfSight(transform, offset.Value, objects[i], targetOffset.Value, usePhysics2D, ignoreLayerMask.value, drawDebugRay.Value);
    3.                         if (hitTransform != null) {
    4.                             // the object has a magnitude less than the specified magnitude and is within sight. Set the object and return success
    5.                             returnedObject.Value = objects[i];
    6.                             return TaskStatus.Success;
    7.                         }
    And particularly the "if (hitTransform != null)" returns true if basically anything blocked LOS. It does not check if the returned transform is actually the target transform. So in my case Enemy Collider or a Wall can return positive on LOS.

    Is this a bug, or am I doing something wrong with my setup?
    For ignoreLayerMask I understood I should place here the object layers I don't want to be checked for LOS.
     
  2. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  3. Hellwaiker

    Hellwaiker

    Joined:
    Jan 8, 2016
    Posts:
    118
  4. adamstepinski

    adamstepinski

    Joined:
    Aug 7, 2015
    Posts:
    57
    I have a problem:
    I use a few scenes (one for lighting) and when I load first enemy, Behavior Manger is created in my scene for lighting

    but then I unload scene for lighting and load a different lighting scene so Behavior Manager is destroyed
    and all behavior trees stop

    The only option I see is checking
    Code (CSharp):
    1. BehaviorDesigner.Runtime.BehaviorManager.instance == null
    and then creating a new Behavior Manger by disabling and enabling all Behavior Tree components in the scene, is there a better way?
     
  5. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    Load a separate scene with the manager first. Then load rest of the scenes.
     
    adamstepinski likes this.
  6. z_yq

    z_yq

    Joined:
    May 3, 2017
    Posts:
    16
    upload_2020-11-16_10-36-3.png
    I'm getting the above error while using it. How do I fix it?
     
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
  9. knas01

    knas01

    Joined:
    Feb 24, 2018
    Posts:
    236
    Hi, I wonder a bit how this asset can collect data from the scene to make the decisions. I'm looking for an AI for a turnbased game, and I want something that can create a heat map that ranks the tactical importance at any certain spot based on line of sight, different cover and so on. Is this something that can help me out?
    Cheers.
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You can definitely do that with a custom task, and then include it in the behavior tree flow. Behavior Designer tasks are similar to MonoBehaviours so if you have scripting experience it should be no problem in order to pick up. This page has the details for how to create a custom task: https://opsive.com/support/documentation/behavior-designer/writing-a-new-conditional-task/

    There is also integration with Bolt and Playmaker if you prefer visual scripting.
     
  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    In 2018 we deprecated a complete Behavior Designer project from the Asset Store because it was using a previous version of the character controller. It took us awhile but we finally updated it to version 2 of the controller and are close to a complete release. The Deathmatch AI Kit has been released on the Opsive Store so if you want to get it early you can do so now.



    The Deathmatch AI Kit includes a set of behavior tree tasks with one goal: eliminate all enemy targets. In order to accomplish this goal the agents will move in formations, take cover, determine the best weapon, and strategically attack the target. The Deathmatch AI Kit allows for team-based and free-for-all deathmatch games using the power of Behavior Designer and the Ultimate Character Controller.

    https://opsive.com/assets/deathmatch-ai-kit/
     
    TonyLi likes this.
  12. studentvz

    studentvz

    Joined:
    Dec 14, 2014
    Posts:
    149
    The Deathmatch AI Kit with Behavior Designer, how heavy is it for mobile? I'm making a mobile game and I'm currently in search for AI that is not to heavy on performance.
     
  13. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Most of the processing time spent relates to the animator rather than traversing the behavior tree. I haven't profiled it on mobile yet but I can do so before an Asset Store release.
     
  14. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I am attempting to use PolyNav2D with Behavior Designer (with Movement Pack) and I have no idea how to approach this. Is this information out of date now?

    -----------------SOLVED--------------------------

    In case anyone else sees this, it wasn't immediately obvious to me but you have to download an addon from Opsive after entering your invoice number. I have started down the path of this starting to work.
     
    Last edited: Dec 8, 2020
  15. jnbbender

    jnbbender

    Joined:
    May 25, 2017
    Posts:
    487
    I have had behaviour designer for some time now and I am finally playing with it. I am also looking at Emerald AI for my game as well.
    I cannot seem to find any videos or documentation that explain how animation fits in. All tutorials show is how to make a behaviour tree and moving a bunch of blocks around.
    The only time I've seen an Npc animated was the Orc in the demo.

    Is there anything that explains how animation hooks in? Emerald AI uses it as it's basis but then again doesn't seem to be as powerful.

    Thanks
     
  16. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    This page explains animations:

    https://opsive.com/support/documentation/behavior-designer/syncing-animations/

    For further questions if you can post on the opsive forum that would be great. There have been some animation topics on the forum so I also recommend taking a look there for how others have approached it.
     
    jnbbender likes this.
  17. YuriiIhor

    YuriiIhor

    Joined:
    Sep 1, 2017
    Posts:
    4
    Hello, I face one trouble with tactics pack. I don't know why, but my surround task acts like ordinary attack. What's wrong? By ordinary attack - I mean that my AI mobs do not surround player, but just run toward him.
    I was recommended to try adding a run till complete node as a parent to Surround, but I dont have this node.
    Help, please. Thanks in advance!
     

    Attached Files:

    • 3.png
      3.png
      File size:
      108.2 KB
      Views:
      314
    leslviv likes this.
  18. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  19. Yakuzza

    Yakuzza

    Joined:
    Mar 10, 2013
    Posts:
    8
    Hi Opsive! Is Behaviour Designer flexible enough to make an AI similar to Jack's from Resident Evil 7? Basically, it's an AI with a melee weapon that resurrects shortly after death and continues looking for the player.
    Thanks!
     
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Thanks for taking a look at Behavior Designer!

    Yes, I can't see any reason why a behavior tree wouldn't be able to handle that type of AI :) We have a character controller asset and with that asset I created a fairly in depth video showing how the integration tree works. I can see you using a tree similar to this for your AI (though this tree may contain more than you need).

     
    Yakuzza likes this.
  21. jean-rodrigues

    jean-rodrigues

    Joined:
    Jan 12, 2019
    Posts:
    8
    Hi, quick question about using behavior designer in 2d platformer type of game specially regading movement pack.
    Is there a way to make it work without customizing it? I mean for instance, when I use "Can See Object" Task and I flip the character, it doesnt flip accordingly and it remains looking to the other side. I had to multiply all offsets by -1 manually to make it work. Just asking to see if there is a better way to do this.

    Thanks
     
  22. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    Last edited: Feb 7, 2021
    opsive likes this.
  23. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    TextusGames likes this.
  25. ArcherSS

    ArcherSS

    Joined:
    Apr 7, 2018
    Posts:
    39
    Hi, I'm a little confused about conditional abort. Below image is the example on document. Let's say at first time, "Can See Object" evaluates to Success, then Action(assume it to attack) begins to execute, in OnStart method, I play a attack animation, and start a timer to hurt the target at certain time periodically. Then at some time, "Can See Object" evaluate to Failure, the Action will be aborted immediately, OnEnd is called, I stop the animation and the timer. But if "Can Hear Object" also evaluate to Success, the Action will enter and execute again, and will repeat the OnStart, the animation and timer will be reset to start. If animation and timer is on half way when previous abort occur, this will cause incorrect behavior. Logically, Action is always valid, but with conditional abort, it experiences in-out-in stages. More generally, with conditional abort, Action's OnStart is not guarantee that the action is first execute, and OnEnd is not guarantee that action is really to the end. One solution is to use states to know if the action is enter or leave attack state. But if we rely on states, why not just use FSM?



    I think I have some misunderstanding on how to use behavior tree correctly, so could you please show me how to use action with conditional abort, for example to solve this problem? Thanks in advance!
     

    Attached Files:

  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  27. lzardo2012

    lzardo2012

    Joined:
    Apr 11, 2013
    Posts:
    80
    Hi, I bought your assets a while ago, but just started trying to implement it in my RTS style game.

    I´m also using Astar pathfinding project pro as well, using the integration, but I have a few questions:

    1) there´s just an integration for the "Movements pack", which is great, but, if I want to use Formations and Tactics pack as well? Or I don´t need any integration for those and can use them as well?

    2) Using SEEK in my units I can make them move to a point close to the enemy unit (using a variable I called attackRange, the unit stops when reach such distance. BUT the unit´s velocity as seen for the AStar component does not return to zero, it´s still the same as the speed I set the unit to move, why? and is there a way to make the unit REALLY stop, because it looks more like it´s being hold in place but still trying to move, sliding in place or something...

    3)I needed a more advanced movement, for example, like a tank, rotating and just moving forward or backward, right now the models are dragged in the direction the path is pointing and it´s probably a navmesh problem (an astar problem too) but is there a node that does this? I mean, tell the unit to point in the direction it should move and them move instead of dragging it at the same time it rotates?


    Thanks!
     
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  29. Supergrubman

    Supergrubman

    Joined:
    Jan 2, 2014
    Posts:
    20
    Does Behavior Designer work with Third Person Controller?
    I don't have enough money to by Ultimate Character Controller.
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Yes, it does :)
     
  31. XGurem

    XGurem

    Joined:
    Dec 5, 2018
    Posts:
    9
    It seems there might be a bug in the latest version. The play task won't play my animation despite the fact that I assigned the game object and name of the animation that should be playing. Both the animation itself and the animation state have the same name so it shouldn't have a problem finding it.
     
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  33. M3N0SA

    M3N0SA

    Joined:
    Dec 11, 2014
    Posts:
    2
    Hi,
    I am looking to download the playmaker integration...
    But none of the links on the download page work https://opsive.com/downloads/?pid=803
    I was wondering if you can point me in the right direction.

    cheers ZX
     
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    That's the right page - make sure you enter your invoice at the top :)
     
    M3N0SA likes this.
  35. kjorrt

    kjorrt

    Joined:
    Nov 26, 2014
    Posts:
    34
    Hi,
    Sorry if this has been asked before but I have moved my project across machines and Unity versions and seem to have lost all of my behaviours. I still have access to the old setup so all is good but I want to get them on to the new machine and U3D version.

    My question is: where are the behaviours that we create stored? I restored the old version of BD but my behaviours are still missing. Are they in a database somewhere?
     
  36. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  37. kjorrt

    kjorrt

    Joined:
    Nov 26, 2014
    Posts:
    34

    Sure. Thanks for replying.
     
  38. Dimonasdf

    Dimonasdf

    Joined:
    Aug 16, 2018
    Posts:
    5
    Hello.
    I would like to be able to color tasks in external behavior trees automatically. However, when I run my test code, it does not quite work. Here's what I have:

    Code (CSharp):
    1.     [Button]
    2.     public void PaintTree(ExternalBehaviorTree tree)
    3.     {
    4.         var tasks = tree.FindTasks<Decorator>();
    5.         foreach (var task in tasks)
    6.             task.NodeData.ColorIndex = 1;
    7.        
    8.         // UnityEditor.EditorUtility.SetDirty(tree);
    9.  
    10.         var assTask = tasks[0];
    11.         Check(assTask);
    12.  
    13.         StartCoroutine(AreEqualLater(assTask));
    14.     }
    15.  
    16.     IEnumerator AreEqualLater(Task _assTask)
    17.     {
    18.         yield return new WaitForSecondsRealtime(3);
    19.  
    20.         Check(_assTask);
    21.     }
    22.  
    23.     void Check(Task __assTask)
    24.     {
    25.         Assert.AreEqual(1, __assTask.NodeData.ColorIndex);
    26.     }
    When I'm looking at Editor window, all Decorators stay grey (default, index 0). When I hover mouse over it, they turn red (index 1) for a brief moment, and then turn grey again. Both assertions check out, but that's not what I see in BT Editor. Red color is not saved.
    I've tried doing the same with closed window, tninking it may interfere somehow (like, repainting every task to its color ongui update, dunno), but when I open editor with my external tree after running PaintTree() on it, all tasks are still grey.
    [Button] is Odin Serializer attribute, showning my method in a component on a gameobject, allowing me to drop any external BT into it.
    I am not in Play mode.
    SetDirty() doesn't seem to be doing anything useful.
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  40. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Are there any good examples of character controllers set up to work with Behavior Designer? Thanks.
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
  42. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    999
    Thank you for your reply, I've checked out the integration. It's a very through example and explanation of the behavior tree itself. At this point I'm just trying to hook into the character animation. There are a lot of components attached to the example character and I couldn't find what I was looking for. The attached script is what I used to use, I think it's the original mechanim example. Can you provide a simple example of controlling the root motion of a character with behavior designer? Thank you for your time.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Locomotion
    5. {
    6.     private Animator m_Animator = null;
    7.    
    8.     private int m_SpeedId = 0;
    9.     private int m_AgularSpeedId = 0;
    10.     private int m_DirectionId = 0;
    11.  
    12.     public float m_SpeedDampTime = 0.1f;
    13.     public float m_AnguarSpeedDampTime = 0.25f;
    14.     public float m_DirectionResponseTime = 0.2f;
    15.    
    16.     public Locomotion(Animator animator)
    17.     {
    18.         m_Animator = animator;
    19.  
    20.         m_SpeedId = Animator.StringToHash("Speed");
    21.         m_AgularSpeedId = Animator.StringToHash("AngularSpeed");
    22.         m_DirectionId = Animator.StringToHash("Direction");
    23.     }
    24.  
    25.     public void Do(float speed, float direction)
    26.     {
    27.         AnimatorStateInfo state = m_Animator.GetCurrentAnimatorStateInfo(0);
    28.  
    29.         bool inTransition = m_Animator.IsInTransition(0);
    30.         bool inIdle = state.IsName("Locomotion.Idle");
    31.         bool inTurn = state.IsName("Locomotion.TurnOnSpot") || state.IsName("Locomotion.PlantNTurnLeft") || state.IsName("Locomotion.PlantNTurnRight");
    32.         bool inWalkRun = state.IsName("Locomotion.WalkRun");
    33.  
    34.         float speedDampTime = inIdle ? 0 : m_SpeedDampTime;
    35.         float angularSpeedDampTime = inWalkRun || inTransition ? m_AnguarSpeedDampTime : 0;
    36.         float directionDampTime = inTurn || inTransition ? 1000000 : 0;
    37.  
    38.         float angularSpeed = direction / m_DirectionResponseTime;
    39.        
    40.         m_Animator.SetFloat(m_SpeedId, speed, speedDampTime, Time.deltaTime);
    41.         m_Animator.SetFloat(m_AgularSpeedId, angularSpeed, angularSpeedDampTime, Time.deltaTime);
    42.         m_Animator.SetFloat(m_DirectionId, direction, directionDampTime, Time.deltaTime);
    43.     }  
    44. }
     
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  44. toyhunter

    toyhunter

    Joined:
    Mar 5, 2018
    Posts:
    76
    Hi @opsive

    Bought BD and Move Pack yesterday and it seems a great asset to speed up my process of AI implementation.
    Now I need to pre-defined some custom typed variables for the behavior tree of NPCs. Given that I already read your doc and youtube tutorial.

    Is there any Best Practice of doing so? Is it "Shared Variable"?
    For better logic management, I need to add PlayerControl variable and it has to be accessible throughout the whole tree. Thanks and please keep on your great work!
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Hello,

    Definition - for support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better.

    Justin
     
  46. Evgeno

    Evgeno

    Joined:
    Sep 8, 2014
    Posts:
    57
    Hello. Once upon a time I saw a message that version 2 is being prepared. Can you find out what the underlying benefits will be and when will the release be?
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Version 2 is still in development, though it is a ways off. It will use DOTS on the runtime side of things and right now we're not sure where DOTS is headed. Once Unity gives some more direction I will continue the development. I have the editor piece really far along using visual elements.

    In other news I am working on version 1.7 of Behavior Designer and hope to have that out soon.
     
    Last edited: Jun 30, 2021
    Sylmerria and Duffer123 like this.
  48. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I hope you keep a version that is DOTS free unless I am misunderstanding how tightly integrated DOTS has to be?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    One of the requirements of version 2 is that it must still support MonoBehaviors. So the goal is to have the core part of the tree be based on DOTS, and then you can either use a MonoBehavior-based approach for the tasks or a DOTS-based approach.

    With that said, a lot of this depends on the future direction of DOTS which Unity hasn't given a status update in awhile.
     
    Duffer123 and Sylmerria like this.
  50. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Progress on version 1.7 of Behavior Designer has been going well and one of the things that will be included is the Stacked Conditional task. The Stacked Conditional task allows you to group multiple conditional tasks in one task which is really useful for conditional aborts. Instead of using nested conditional tasks you can now use a single task. StackedConditional.png