Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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:
    5,122
    Andreas Metz created a Udemy course called Practical Guide to AI in Unity and in his course he used Behavior Designer. I am still going through it but I thought that I'd like everyone know about the course:

    https://www.udemy.com/course/ai-in-unity

    Andreas gives a good overview in the different AI techniques and then dives deep into behavior trees using Behavior Designer.
     
  2. P3ndragonLLC

    P3ndragonLLC

    Joined:
    Sep 19, 2019
    Posts:
    99
    Hello, is it possible to use the behavior designer to follow a spline path and apply actions based on doing a state check at various points? At runtime, I get a list of markers with transforms I can supply behavior designer for the path/points from the spline editor.

    Thanks!
    Scott
     
  3. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    This sounds really similar to the integration with Simple Waypoint System. There aren't any tasks built-in that will do this, but for Simple Waypoint System I created a new set of actions. If you have scripting experience this is pretty easy to do.
     
    P3ndragonLLC likes this.
  4. mc6251

    mc6251

    Joined:
    Dec 13, 2018
    Posts:
    3
    I cannot click Random Float or Random Int. They didn't show in the Editor. However, I can click random bool and random string.
     
  5. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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
     
  6. hertz-rat

    hertz-rat

    Joined:
    Nov 3, 2019
    Posts:
    71
    My gamejam team and I are wondering how you go about managing animation state with behaviour trees like BD. Specifically, in the case of aborts or moving through the behaviour tree more quickly than expected, what is a practical way to keep track of your mecanim state so you don't stack a bunch of triggers or attempt invalid transitions?
     
  7. opsive

    opsive

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

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better. Also, there's a section in the docs on animation so that page should help :) https://opsive.com/support/documentation/behavior-designer/syncing-animations/

    Justin
     
    Last edited: May 4, 2020
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
  9. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    Hi how would I go about integrating this with puppetmaster/final ik?

    In my case when my character loses balance, BehaviourPuppet will fire an event 'onLoseBalance', is there a way for the BT to listen to it? so i can set variables like 'isStandingUp' to false?
     
  10. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    183
    Can I use this for enemy grid based movement? Ie. No diagonal movement for pathfinding?
     
  11. opsive

    opsive

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

    For support can you post on the the opsive forums at https://opsive.com/forum? This allows me to track each request better. For events you can use something like this: https://opsive.com/support/documentation/behavior-designer/events/

    Justin
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Behavior Designer doesn't do any of the actual pathfinding, it's up to the underlying pathfinding algorithm to do it. With that said, I believe that the A* Pathfinding Project has the ability to move based on a grid so you could use the A* integration.
     
  13. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    183
    Thanks @opsive that works great. Another question, does your tactical pack work with/alongside the A* Pathfinding Project?
     
  14. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Yes, it does.
     
  15. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    I'm running into kind of an annoying thing about the "Task" base class: It implements OnDrawGizmos. Because of this, every single Task subclass in the project results in another entry in the Gizmos dropdown, which seems to really slow things down in Unity 2019.3.

    Since Task is defined in an assembly, I don't have the option to manually change this. Does Task need to implement OnDrawGizmos? I don't see how it makes sense, since it's not an object I can put in the scene view anyway. Any chance this could easily be removed from Task to avoid blowing up the Gizmos dropdown?
     
  16. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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
     
  17. purnapatadia

    purnapatadia

    Joined:
    Jul 20, 2017
    Posts:
    7
    Hello @opsive
    I am getting below error when instantiating a prefab that contains Behaviour Tree in scripting backend il2cpp. It works fine for Mono. The error is observed in android only and not in the editor.

    Thanks in advance.

    MissingMethodException: Default constructor not found for type UnityEngine.Collision
    at System.RuntimeType.CreateInstanceMono (System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in <00000000000000000000000000000000>:0
    at BehaviorDesigner.Runtime.JSONDeserialization.ValueToObject (BehaviorDesigner.Runtime.Tasks.Task task, System.Type type, System.Object obj, BehaviorDesigner.Runtime.IVariableSource variableSource, System.Collections.Generic.List`1[T] unityObjects) [0x00000] in <00000000000000000000000000000000>:0
    at BehaviorDesigner.Runtime.JSONDeserialization.DeserializeObject (BehaviorDesigner.Runtime.Tasks.Task task, System.Object obj, System.Collections.Generic.Dictionary`2[TKey,TValue] dict, BehaviorDesigner.Runtime.IVariableSource variableSource, System.Collections.Generic.List`1[T] unityObjects) [0x00000] in <00000000000000000000000000000000>:0
    at BehaviorDesigner.Runtime.JSO

    The behavior "Behavior" on GameObject “goName” contains no root task. This behavior will be disabled.
     
    Last edited: May 16, 2020
  18. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    3 Questions:

    1. Is there any way to put a break point in a tree? Similar to your tutorials, I have a series of branches with Lower Priority conditional abort Sequences all lined up on a always Repeating Selector. I'm having a very tough time figuring out which branch and which task is causing the tree to abort. I guess my question is do you have any recommendations for debugging trees? I can move step by step with Play mode paused but the Tree editor does not correctly highlight tasks when doing that. Highlighting only runs accurately when the game is running.
    2. Is there any chance you can do an update where if a property in game code is changed, the connected Tree variable shows an error or goes Null? I make extensive use of properties in code to communicate between Trees and my game code. When I change the name of a property in a class that is connected to a Shared variable in the Tree, the Tree variable stays connected to the previous named property that no longer exists. If I forget to reconnect the Tree variable to the newly named property, the Tree runs fine but of course the variable has no effect so the Tree does not run correctly......much debugging ensues.
    3. Another nice option would be to be able to see the ExecutionStatus of a Tree in the editor somewhere. This is a problem when you use the Pause When Disabled option in the Tree component. When Paused, the Tree tasks are still highlighted and it can be difficult to tell if anything is still running.

    Thanks
    Allan
     
    Last edited: May 17, 2020
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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
     
  21. Dimonasdf

    Dimonasdf

    Joined:
    Aug 16, 2018
    Posts:
    5
    Hello.
    Could you please explain something on this is example? Let's say we have about 70 AIs which are initialized when you enter some place. Their activation is spread along 15 frames, so it's about 4 to 5 enemies activating per frame. And then there is this code running in an assisting component on each AI
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         MaxLookAtRotationDelta = (SharedFloat)behaviorTree?.GetVariable("MaxLookAtRotationDelta");
    4.     }
    In each frame it takes 30-46ms to compute and has 24000-30000 calls to GC with 1.1-1.4MB allocation. I realize you are using reflections to access variables inside trees, but this is clearly over the top performance hole, don't you agree?
    Is there maybe something that we don't understand, or is there some way to improve variables' read/write performance? Because there is a lot more going on in our system than this rotation speed caching.
    Any insights and tips will be greatly appreciated, thanks.
     
  22. opsive

    opsive

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

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

    Justin
     
  23. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    100
    same question. I went to your forum but can't find any search field.

    edit: Using google "opsive forum [ my keyword ]" found the post i was looking for.
     
    Last edited: May 27, 2020
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
  25. Guerrilla705

    Guerrilla705

    Joined:
    Jan 23, 2014
    Posts:
    8
    Are there callbacks for OnEnter and OnExit of an action task? I can't seem to find any, but that seems like basic BT functionality. If not, are there any best practices way to trigger an event (like begin a melee from an external melee system) right when the behavior is entered? I can put calls to my own OnExit whenever I would call a return TaskStatus.Success or return TaskStatus.Failure, but I also want to be able to run OnExit when the task is exited for other reasons (interrupt, conditional abort, etc.)
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Does any of your assets/packages contain a "Target can see ME" action? I've tried to look around before buying in but I can't seem to find anything on it.
     
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    It sounds like you are looking for the Can See Object task. There is a version of this task included in the tutorial resources download (seen in this video), and then the Movement Pack contains a more advanced version of this task.
     
  29. flipwon

    flipwon

    Joined:
    Dec 29, 2016
    Posts:
    179
    Sort of, but instead of can see object, looking for object looking at me funcitonality. Wouldn't be too hard to implement I guess with everything else, so I'll probably go ahead and do it. I'm assuming all the other tasks you've created are open to look at?
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    So it's almost Can See Object in reverse? In this case Can See Object doesn't include this functionality, but it wouldn't be too hard to modify to change the targets for what is looking at what. All of the source for the tasks is included.
     
  31. a-t-hellboy

    a-t-hellboy

    Joined:
    Dec 6, 2013
    Posts:
    180
    Hey there,
    Is it possible to write Conditional task and use OnFixedUpdate in it ?
     
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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. batesnik

    batesnik

    Joined:
    May 5, 2020
    Posts:
    1
    I just got the assest. Just testing it out with the basic seek task. When I hit play the npc just goes straight into the air.
    Why is it doing this
     
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    I responded to your post on the opsive forums - thanks for posting it there!
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    I responded to your post on the opsive forum - let's keep the discussion there as it makes it easier to manage.
     
  36. Crocomodo

    Crocomodo

    Joined:
    Nov 21, 2017
    Posts:
    29
    Can someone tell me why should I use this asset? When I have all gazillion number of states for NPC? I consider buying it but I don't know if I really need it.(I'm gamedev noob)
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    If you don't need it I recommend waiting until you do :)

    Behavior Designer is a behavior tree implementation for Unity. Behavior trees are an extremely versatile AI implementation that were first made popular by Halo 2. I recommend taking a look at the Behavior Designer videos/documentation to see if it's something that would benefit your project. If you have any specific questions feel free to ask!
     
  38. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    I got a custom system totally data oriented and gameobjects only appear when the local player's camera is looking at them, and I wonder if the behavior designer can be modified to use without gameobjects.
    Basically is that can I assign a behavior tree to a certain type of my ai, and I call all the behavior tree's execute functions through an ai manager?
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Behavior Designer uses MonoBehaviours out of the box, but I have heard of people modifying the runtime source to not require the UnityEngine at all.
     
  40. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Great to know, any directions you can point for me to check out?
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    I haven't tried to strip the UnityEngine out of it but besides the Unity API tasks there are really only two classes that use MonoBehaviour (BehaviorTree.cs and BehaviorManager.cs) so I would start there.
     
    Harekelas likes this.
  42. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    Is there any reason why in 6 years you haven't updated the tutorials or added more?

    Edit: Even now I've just tried to learn via the CTF tutorial and the red defenders do nothing. The map had to be re-baked, and again my learning has come to a halt. After dropping €70+ on this I expect a little bit more from the tutorials.
     
    Last edited: Sep 2, 2020
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    What are you interested in? The original videos are still relevant today. I create the videos based on the number of requests for a particular topic that I receive. There hasn't recently been a lot of a requests on a single topic to make a video out of it. In general once you understand the behavior tree flow everything fits in naturally.

    Somewhat recently I created a set of "Behavior Tree Baiscs" videos which walk you through some of the common tasks. You can see the start of those videos here:



    In addition I created a video showing the integration with our character controller. This video is useful for a general behavior tree design strategy even if you aren't using our character controller:



    The navmesh will need to be baked. I just tried that sample out and it worked - if you are hitting issues with it feel free to post on the opsive forum.
     
  44. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    I'd be interested in a short concise series (4/5 videos long, if even) where you layer up branches showing the process of evolving the tree whilst explaining some more functionality, logic and application of the other nodes.
    I'm coding 3 years and no where near excellent but I can pick things up rather quickly. I've written a few task nodes that work fine for finding random positions etc.

    That's the reason why I'm posting here, I've had difficulty understanding the concepts from your 2017 video series and have had trouble using your tutorials. I believe that there may be more like me who probably won't post about it.

    Following along with that involves buying another Add-On and it won't make sense for me to buy more if Behavior Designer isn't correctly understood.

    What version of Unity are you using?

    I'm using 2020.1.1f1.

    In regards to Behavior Tree, I'm sure it is a great piece of kit once the concepts are understood. If Behaviour Tree is specifically created for advanced or professionals then so be it but if it's created to appeal to all levels from intermediate up then I really do think a short series would greatly help to broaden the scope of your audience. :)
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    Thanks for letting me know - I've written it down :)

    That's true. Even without the character controller though that's a good explanation of how a more complex behavior tree works. You won't be able to play with the sample scene without the character controller but it's still a good resource for the general behavior tree flow.

    Ah, that was the cause. I had to make a couple of tweaks to get it working in that version. If you download the sample again everything should work. Thanks for letting me know.
     
  46. auzzymo

    auzzymo

    Joined:
    Nov 19, 2017
    Posts:
    17
    Just had a look at the character controller video and I must say it’s perfect. I never looked at the video as I wrongly assumed it wasn’t what I could use. It is essentially the 4-5 videos I spoke about just as one video of 23 mins. So, great

    Getting the hang of it now.

    I try the tutorials again later, glad I could help!
     
    opsive likes this.
  47. adamstepinski

    adamstepinski

    Joined:
    Aug 7, 2015
    Posts:
    57
    Hey,

    Is Owner always the same as this.transform from inside an Action task?

    I looked in the forum & documentation but didn't find the answer
     
  48. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122
    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
     
  49. CommunityUS

    CommunityUS

    Joined:
    Sep 2, 2011
    Posts:
    240
  50. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,122