Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Behavior Designer - Behavior Trees for Everyone

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

  1. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    It's not that you can't use it, it's more that for the same level of integration that Playmaker has it'll probably take some custom tasks. Adding Bolt integration really will be just some custom tasks and no core Behavior Designer changes so if you have scripting experience you could create the custom action or conditional tasks.
     
  2. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    623
    Hopefully some out-of-the-box integration for Bolt comes soon :p
     
  3. Thermos

    Thermos

    Joined:
    Feb 23, 2015
    Posts:
    51
    Hi, I've been using behavior designer over a year, it's a very nice tool.

    But I have some suggestions, I think it would be nice to have "Private" variables. I usually create some variable just for passing values inside a tree. I don't want them to be shown on the inspector but it's currently impossible to do that. My solution is to name them like "s_character_hp" (serialize) for public, and "t_int_1" (temp) for private, but still it's more comfortable if behavior designer could support this feature or at least support variable grouping on the inspector.

    Thanks.
     
  4. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    623
    +1

    Yes, that would be nice!
     
  5. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    @Thermos - thanks for the suggestion! After we get version 2 of our character controller out we have pretty major plans for Behavior Designer and this fits in perfectly :)
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,489
    Hi. @opsive

    I got the BD with Movement pack for free, but I can't seem to find my way to download the latest movement pack again.

    Can you help?
     
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Please send me an email or PM with your invoice number and I'll send you the updated link.
     
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Behavior Designer 1.5.11 has been released on the Asset Store. The release notes can be found within this post.

    We will also have a booth at Unite Austin so make sure you stop by and say hi! I'd love to also hear about how you're using Behavior Designer.
     
    TonyLi likes this.
  9. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    215
    Hey, guys. i have a reoccurring problem with the Behavior designer.

    Sometimes when i have multiple game objects with different Behavior trees in the scene then one of those trees seems to be starting but it seems that it is actually not doing the task.

    For instance, if I place the "Wander" task on multiple gameobjects some of the objects look like they have started wandering but actually doesn't move. if I then (while the game is running) disable and then enable the gameobject again the task runs as it should.

    Can you tell me if it's something that I've done wrong or a known issue?
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Each behavior tree operates independently so for your tree the wander tasks won't know about each other. Did you select Start When Enabled on each component? If it is enabled are you able to reproduce the issue by creating a fresh scene, adding a plane with a NavMesh, and then adding multiple wander GameObjects?
     
  11. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    215
    Yes the Start when enabled is on. And i can reproduce it with a single plane in a fresh scene :(
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Can you attach just the scene file to this thread? No need to include Behavior Designer or bake the navmesh. I'll then take a look at it and let you know.

    (Edit: I've attached a package which has a couple of duplicated wander agents. Can you reproduce it from this scene?)
     

    Attached Files:

    Last edited: Oct 3, 2017
  13. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    I’m currently making a zombie game and currently have around 40 navmesh agents with my own wander and follow code.​

    I want to add more complex behaviors, but need it to perform well.

    A few questions...
    1. Ability for zombies to chase player and take different paths to the player
    2. I have a survival mode. Is it possible to have zombies wander towards a player and look as if they are searching , initial the get a certain distance ( Navmesh distance not Vector3 distance)
    3. My game is a vr game, so resources are tight. Is there a way to control how often the AI gets updates?
     
  14. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    303
    1, 2: the movement pack does this and more
    3. Yes, you can specify the time in seconds or 'tick' the trees in a custom way
     
    opsive likes this.
  15. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361

    Cool thanks!
     
  16. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    Does anyone know who easy it is to learn this system?
    I own ICE...and found that to be a 2 - 3 day learning experience, but also found out that its not suitable for my game.
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Behavior trees are an industry standard for AI so there is a learning curve but there are a good amount of resources online for how behavior trees work. I'd recommend taking a look at this page which has a set of resources that are more geared towers Behavior Designer. Let me know if you have any specific questions and I should be able to help answer:

    http://opsive.com/assets/DeathmatchAIKit/documentation.php?id=3
     
  18. wood333

    wood333

    Joined:
    May 9, 2015
    Posts:
    642
    I'm trying to figure out which ai to use with my project. I own a few but there is controversy because whether they will work for me depends on updates I am waiting for. I have been aware of BD for a while, and a comment (on an unnamed competitor site) said this, referring to BD.

    Tell me, how long will it take me to setup an AI using BD that does the following:
    > Eat
    > Sleep
    > Run when hurt
    > Fight when cornored
    > Give birth
    > Grow /change over time
    > Wander
    > Flock when within range of other similar creatures

    And how large and unwieldy would this tree be? I shudder at trying to imagine. Lol


    First, can your respond to their criticism, as to how challenging that would be..

    Second, doesn't BD have ways to pack a large group of nodes into a master node, and other ways to keep a large tree manageable?
     
  19. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    There are a couple of different ways you could approach this. The Utility Theory sample project actually has an example of eating, sleeping, and working which covers a couple of the cases. Here's a picture of that tree:

    DecoratorScreenshot.png

    You could also structure it so instead of using Utility Theory you use standard behavior tree tasks. This would be similar to the Third Person Controller or Deathmatch AI Kit tree. The deathmatch tree in particular is pretty large but it has a lot of functionality to it. In the end it is really just adding a new branch to the tree for each action (run, fight, etc) so the tree may be large but it's pretty easy to setup and debug once you know the behavior tree structure.

    It does - you can use external trees for this case which are basically subtrees.
     
    TeagansDad, DonLoquacious and wood333 like this.
  20. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    303
    These are pretty much exactly the behaviors I did with BD. I have each of the behaviors as an external tree that I just reference in a master tree on the animal. Once the tree loads all the external trees at runtime it can get quite huge if you dont collapse sections of it.
    If you have not dealt with behavior trees it might take you some time to get a hang of, but I can tell you that you will get better performance with BD compared to using the competing asset. It is also a lot easier to extend BD and create whatever actions you might need with your own scripts.
     
  21. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    130
    is there a way to make coroutine or invoke ?
    how to get component like HealthBar.cs and call method in this class
    Is there enum variables ?
     
    Last edited: Oct 8, 2017
  22. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Within the task? Yes, there is coroutine support. I haven't added Invoke support because you can do the same with coroutines but I can add it to the next release.

    You can use GetComponent similar to a regular MonoBehaviour class.

    Yes, you can use enums.
     
  23. Cartoon-Mania

    Cartoon-Mania

    Joined:
    Mar 23, 2015
    Posts:
    305
    I have something to say about utility AI. Utility AI example is too poor. The manual is also poor. Of course, you seem to think of this as a bonus. If so, it does not matter. I understand that the utility AI was created for use by someone already familiar with it. But if you have included the function for "EVERY ONE" please add examples and manual for UTILITY AI. I would like to use UTILITY AI, but I can not do anything with the example and manual now.
     
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Take a look at this paper which I used to implement the Utility Selector. I thought that I linked to it from the documentation but it doesn't look like I did so I'll do that now. This paper gives a very detailed description on how to use the Utility Selector, which is the same implementation that Behavior Designer uses.
     
  25. Cartoon-Mania

    Cartoon-Mania

    Joined:
    Mar 23, 2015
    Posts:
    305
    To be honest, the utility AI is hard to understand for me. I bought three utility AI-related assets from the Asset Store. Fortunately, I understood DecisionFlex. If you want others to use Utility AI in the behavior designer, see the DecisionFlex tutorial. The iperson example has been a great help to me. I would like to have such examples and tutorials in the behavior designer.

    EDIT The combination of behavior tree and utility AI is a wonderful idea. The advantages of both become larger and the disadvantages of both become smaller. I know you are really busy. There are many products that you are responsible for. So I do not expect much. But the integration of the behavior tree and utility AI is a fantastic idea. Do not you think you could make a more detailed description and a decent example? DecisionFlex' iPerson example is a good reference.
     
    Last edited: Oct 13, 2017
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    I can definitely add a more in depth tutorial to my list. We are working on revamping our website (the new design looks AWESOME!) and improving the documentation for the utility selector with the new site could go along with it. The existing sample does cover the basics pretty well and has a description of the tree within the scene. Do you have a specific question that I can help with now?

    The basic idea of the Utility Selector is that it'll select whichever branch has the highest value returned by the GetUtility method. In the sample scene there are two trees: one which returns a utility value through the decorator, and another which returns the utility value through the action task. In both of these cases the curve on those tasks are being evaluated and returned within the GetUtility method. The action version of the tree is a little bit easier to understand so I would start with that one - the Evaluate.GetUtility method also has a pretty good description of what it is doing. Hopefully that helps :)
     
    Teila and magique like this.
  27. Cartoon-Mania

    Cartoon-Mania

    Joined:
    Mar 23, 2015
    Posts:
    305
    There is something worrying about utility AI. The problem is performance. Is it ok to use utility AI on mobile too?
     
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Sure, at the heart of it these tasks are just doing AnimationCurve.Evaluate which has a O(1) (constant time) so it's no problem to use.
     
  29. renski

    renski

    Joined:
    Sep 27, 2013
    Posts:
    14
    Not true. There are posts since 2014 asking for vehicle physics integrations inlcuding Edys and nothing showed up. I have been looking at different solutions and I am still not sure if this asset can accomplish it (if so, i am buying it immediatly); a traffic system highway/road type, pedestrians, steering, traffic lights interaction, queing and of course still take into account for vehicle physics. Can this be done, or probably with a combination of packages, any suggestions ?
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Behavior Designer can help with deciding when those actions should be performed, but it would take a lot of work to do those actions without any scripting. You can always extend the action task to create the logic for that system so it could be done with scripting.
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    New Integration: Bolt (Visual Scripting)


    There have been a lot of requests for Bolt (Visual Scripting) by @ludiq and I just finished with the integration scripts. You can download it from the Behavior Designer samples page. This integration allows Behavior Designer to start a FlowGraph, wait on a FlowGraph, send events, and synchronize variables. As you get more into this integration let me know if there is anything else that you'd like to see!
     
    Last edited: Oct 17, 2017
    MasterArty and MarkusGod like this.
  32. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    1,489
    Hi. I am getting the same error for the XboxOne. I guess there is no other way to solve this than importing the source?
     
  33. funkyboy_2017

    funkyboy_2017

    Joined:
    Aug 16, 2017
    Posts:
    1
    How to download it?“”PlayMakerAssets.unitypackage”
     
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    That's correct. I will look at including a runtime build specifically for AOT platforms in the next release so you don't need to do a separate import.
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
  36. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    I'm making a co-op Photon networked zombie game. I want the host's computer to use the behavior tree for controlling the zombies and want the client's computer to NOT use them.

    Question
    1. Is there a way to turn off behavior Tree for only the client? (I know I can just turn off the component on the client), but I want to know if there is anything built in to handle this....just want to make sure I use it the correct way.
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    That sounds like the correct method :)
     
  38. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    164
  39. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    799
    @MarkusGod - Tim has an updated integration package for BD available on his Motion Vault page. Doesn't have quite the elaborate example as this older packs, but it's enough to get you going.
     
    opsive and MarkusGod like this.
  40. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,728
    We are actually attempting Utility Theory right now with Behavior Designer. I handed off a bunch of research I found to Dennis and his engineer brain is now loving it. I will let you know how it goes. We plan to use it with NPCs and integrate into our social code.

    I find it fascinating and so very cool!! I guess you got us back. lol
     
    opsive likes this.
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Awesome.. I'm looking forward to seeing what you guys come up with :)
     
    Teila likes this.
  42. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    Thanks! I am a big time noob to behavior trees...so please don’t mind the basic questions.

    1. I have a NPC that can seek both player 1 and player 2. Once the NPC starts going after one, he never goes after the other. I have the sequence set to Lower Priority, but it never gets re-evaluated.

    2. Can See Object - If I populate "Target Object" it works. If I populate "Target Objects", with 2 gameObjects it works. But when I try to use Target Tag, it never works. Am I supposed to be populating the Target AND Target Tag? By looking at the code, I don't think so, it just never seems to work.

    Update:
    Found Answer for #2. - It looks like when looking for tags, you need to have the layers setup correctly. I changed it from "nothing" to the proper layer and it now works.

    Still need the answer for #1 :).
     

    Attached Files:

    Last edited: Oct 23, 2017
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    I don't think that this would affect it but try to remove the conditional abort from the selector. Here's also a similar tree that you can base yours off of:

    http://opsive.com/forum/index.php/topic,41.0.html
     
  44. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    Ok, removing the Conditional Abort from the Selector worked...thanks!
     
    Last edited: Oct 24, 2017
    opsive likes this.
  45. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    I seem to be a bit dense when it come to behavior trees.

    I want to have my enemy idle unitil he sees the player then pursue the player. This works fine.

    The issue happens after the pursue completes, the enemy never goes back to idle...the tree ends.
    I've tried many combinations of selector and sequence with both check, low priority checked etc...

    How can I have him go back to idle (and ready to pursue if he sees the player again)?



    Also, I noticed that the destination for the navMeshAgent is never null when using the behavior tree. Its set to the navMeshAgent's current location if he is not moving.

    I was previously using navmeshagent.destination = null to have my enemy play an idle animation and when the navMeshAgent.destination was < 1 it would play an attack animation.

    Since its never null and its desitination is now < 1, he is always playing the attack animation when not walking.

    Is there a proper way to handle this? I can code the solution, just need to be pointed in the correct direction...thanks!
     

    Attached Files:

    Last edited: Oct 25, 2017
  46. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Since the seek task completes successfully you'll either need to place a repeater which repeats forever at the root of the tree or select restart when complete on the behavior tree component.

    For a good behavior tree overview take a look at this page:

    http://opsive.com/assets/DeathmatchAIKit/documentation.php?id=3

    It contains links to other behavior tree resources as well as an explanation of a pretty advanced behavior tree.

    Is this happening with the tree that you sent the screenshot of? With the Movement Pack tasks you should never need to directly set a destination position.
     
  47. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361

    Ok will take a look at those behavior trees.

    Yes, it’s happening with the movement pack (and the tree I sent a screenshot of). I’m not directly setting the destination in my code anymore.

    It seems that the movement pack is setting the distination to the navMeshAgents current position if there is no destination. So it’s never null, which is fine. I just need to know how to deal with that in the behavior tree.
     
  48. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Taking the seek task as an example, it will call NavMeshAgent.SetDesination and use the target object's position for that destination. If there is no target object then it'll use the target position variable which will never be null since that's a Vector3.
     
  49. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    361
    Got it and that seems to be what I am experiencing.

    I am now trying to figure out an alternative since that destination value is never null, I have no way knowing if the enemy character is close to the player and should play an attack animation or if the enemy is far from the player (and the vector3 destination is his own position) and I should just play the idle animation.

    How is this usually handled in a Behavior Tree?

    As I mentioned I can rewrite my code to use something else...just don’t know the approach I should take to solve this.
     
  50. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,698
    Take a look at these two pages from the deathmatch tree - it provides a walkthrough of a scenario very similar to that:

    http://opsive.com/assets/DeathmatchAIKit/documentation.php?id=17
    http://opsive.com/assets/DeathmatchAIKit/documentation.php?id=7

    The Third Person Controller tree also contains a similar explanation:

    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=119

    You basically want to avoid calling seek until you know that you have a target to seek towards.