Search Unity

  1. New Unity Live Help updates. Check them out here!

    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,750
    You'll want to implement OnUpdate so the task knows when to return. In the current form it is returning success immediately because OnUpdate is not implemented.
     
  2. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    579
    I'm not sure how should I implement the OnUpdate.
    I tried to add this but it didn't help:
    Code (CSharp):
    1. public override TaskStatus OnUpdate()
    2. {
    3.     return TaskStatus.Success;
    4. }
    This is my current tree, and it was working fine when the damp was inside the OnUpdate method, but camera was badly moving:
    Screenshot 2018-10-02 at 23.11.29.png
     
  3. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    You'll want to return a status of TaskStatus.Running within OnUpdate until you are complete with the damping. It probably makes sense to have this task under a parallel task so other tasks can run at the same type.
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Version 1.6 of Behavior Designer has been released on the Asset Store. You can view the release notes on this page - it contains a number of workflow improvement features such as dynamic variables, a find dialogue, and a quick search window.
     
  5. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    405
    The Find dialogue is huge improvement for my large trees. Thanks a ton for this update.

    Allan
     
    opsive likes this.
  6. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Glad you're already making use of it! I should have attached images to my initial post showing what everything is.

    The Find Dialogue allows you to search by task name, task type, or variable. I really like the variable search because it allows you to find what tasks are using a variable quickly.

    Find.PNG

    The Quick Task Search can be opened by pressing the space bar and it allows you to add new tasks without having to move the mouse. Tasks can be narrowed down with the search and then selected with the arrow/enter keys.

    parallel.PNG

    Dynamic Variables have been added which allow you to declare new variables with a limited scope (likely only used by two tasks). This prevents you from having to add new variables to the behavior tree which are only used temporarily.

    DynamicVariableSelection.png
     
    mcmorry likes this.
  7. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    27
    Is there a way to destroy component? Such as destroying a collider?

    When I pause the behavior, is there a method in the Behavior class to resume() the behavior that I can invoke from my methods?
     
    Last edited: Oct 15, 2018
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    For support can you start to post within the opsive forum? This will allow me to track support requests better :)
     
  9. UserNotHere

    UserNotHere

    Joined:
    Jan 22, 2018
    Posts:
    9
    Couple question hopefully someone can answer. What is the difference between Behavior Designer and Emerald AI. They seem to have similarities but BD has more "stuff". EAI seems to have animator functionality does BD have it likewise?
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    The major difference is how the AI is created. Behavior Designer implements behavior trees which are an industry standard for AI and you can create pretty much any type of AI with it, but you'll have to have an understanding of how behavior trees work and possibly some scripting experience depending on what you want to do. While it is possible I do not recommend using the animator tasks within the behavior tree, take a look at this page for more details.
     
  11. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    2,241
    opsive might be able to answer better, but I've played with both systems, and they're really not the same thing at all-

    Emerald AI is basically a set of pre-built, commonly-used, generic AI behaviors that you can simply attach to your game objects. It's super easy, because you can just slap an component on a character and select a few options and it's ready to go. They have parameters that you can tweak but you are ultimately limited by what is provided.

    Behavior Designer is a framework that you can use to build your own behaviors. It's almost like visual scripting, and you have to learn how it works, but the advantage is that you can build complex a AI that is specialized to your game.
     
    opsive likes this.
  12. UserNotHere

    UserNotHere

    Joined:
    Jan 22, 2018
    Posts:
    9
    Thanks for the responses.
     
  13. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Here's a new video explaining the Ultimate Character Controller / Behavior Designer integration scene. Even if you don't have the Ultimate Character Controller it's still a great resource for learning how behavior trees work.

     
  14. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    27
    Hi, I tried to register but when I clicked "Check Invoice", it says "Could not find invoice. Please enter a valid invoice number to register."
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Can you send me an email or PM with the invoice number that you are using?
     
  16. josh1989

    josh1989

    Joined:
    Jul 22, 2017
    Posts:
    4
    Hi there i am trying to call my different animations in behavior designer and cannot see the bool parameters i created for my animations in animator when i am in behavior designer trying to find them. These are the bool parameter set in animator (walking on, waving on, push button), .

    This is how i think you would set an animation to play when you want it to in behavior designer if i'm wrong about this please tell me all have found is tutorials of people using single objects doing things not triggering different animations when doing so.

    Please help im going nowhere with this, all i want is to animate my character in the space using his different animations when he does different tasks but cannot see how...
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Take a look at this page for animation. If for future questions you can post on the opsive forum that will allow me to better track support requests.
     
  18. josh1989

    josh1989

    Joined:
    Jul 22, 2017
    Posts:
    4
    Thanks for your reply it was helpful and i will be sure to post any future questions at the forum you linked to. Thanks!
     
    opsive likes this.
  19. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    405
    opsive,

    I received the following error when I upgraded my project to Scripting Runtime Version .Net 4.x equivalent in Unity 2018.3.0 b10. Things were working fine in 2018.3.0b10 until I upgraded to .Net4.x. What is very strange is I have 3 characters (Player, Enemy and Pet) in my scene with behavior trees. This error only appears on the Pet so it leads me to think there may be a task on that character that is incompatible with .Net4.x. The other 2 characters appear to work fine.
    When I switch back to .Net 3.5, the error goes away.

    I am using JSON serialization in preferences on all of my trees.

    Do you have any idea what might be causing this error or how to fix it for this character?

    Thanks
    Allan
    NullReferenceException: Object reference not set to an instance of an object
    BinaryDeserialization.LoadTask (BehaviorDesigner.Runtime.TaskSerializationData taskSerializationData, BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Task]& taskList, BehaviorDesigner.Runtime.BehaviorSource& behaviorSource) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.AddToTaskList (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, BehaviorDesigner.Runtime.Tasks.Task task, System.Boolean& hasExternalBehavior, BehaviorDesigner.Runtime.BehaviorManager+TaskAddData data) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.BehaviorManager.EnableBehavior (BehaviorDesigner.Runtime.Behavior behavior) (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.Behavior.EnableBehavior () (at <1cb7df59e12f495fa3a64118298c7b21>:0)
    BehaviorDesigner.Runtime.Behavior.Start () (at <1cb7df59e12f495fa3a64118298c7b21>:0)
     
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Can you start to post on the opsive forum for support? This allows me to track requests better and also allows for better searching.

    My guess though is that your behavior tree is still serialized with an old version. If you switch back to .net 3.5, reserialize the tree, and then switch to .net 4 it should work.
     
  21. Miguelfanclub

    Miguelfanclub

    Joined:
    Jun 14, 2015
    Posts:
    41
    Hi,
    Im doing a FPS dungeon crawler with grid based movement. Its mostly playmaker.
    Im about now to start with enemies AI (patrols etc)
    Can you confirm that with Behavior Trees + A star project I should be able do it?
     
  22. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    405
    opsive,

    Will do. Let me know if you want me to repost this on the opsive forum. In the future, I'll make sure I post to opsive forum.

    You'll need to tell me how to reserialize a tree. I don't really know what that means. I've tried everything I can think of.
    - Unpack the prefab so it's not a prefab anymore, then convert to .Net4.x.
    - Make changes to the tree and Play(I assumed this would reserializes the tree), Apply those changes to the prefab, make sure it plays in 3.5, convert to 4.x.
    - Delete the pet from the scene entirely. Then convert to .Net4.x. Then drag the Pet prefab into the scene.

    I can combine all of these things in different order and nothing seems to work. It's like the Behavior Tree script on the Pet is not recognizing that the tree exists. Even though it works fine with my other characters.

    EDIT: I figured it out. :) The good news is it had nothing to do with 2018.3. The conversion to .Net4.x was corrupting one of my external behaviors. My Pet character was the only one using External Behavior Reference tasks. I was able to narrow it down to the one external behavior tree asset that simply would not convert to .Net4. It was totally corrupted by the .net4 conversion so there was no tree at all. My solution was to re-import that external behavior tree asset from a backup and copy the tree directly into my main tree instead of using a reference task. That fixed the problem.

    Thanks
    Allan
     
    Last edited: Nov 17, 2018
    opsive likes this.
  23. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Behavior Designer is not directly integrated with the A* Pathfinding Project, but the Movement Pack is and that works with any of the grid types.
     
  24. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    266
    Hi using behavior designer for my networked enemies, however the behavior tree will only see the client who is hosting the game and not the connecting client? is there anything specific i should be doing to ge tit to work? thanks

    edit: using Unity networking

    Daniel
     
  25. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    For Behavior Designer support can you post on the opsive forum? This allows me to track the support requests better and allows for better searching.
     
  26. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    266
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    I am prepping the Behavior Designer 1.6.1 release and this release will remove support for Unity 5.6, add support for Unity 2018.3, and also include assembly definitions. Some folders have been moved in order to better support assembly definitions so when you import Behavior Designer 1.6.1 you will first need to remove your previous Behavior Designer directory. If you'd like to get this release before it is sent to the Asset Store feel free to send me a PM with your invoice and Unity version.
     
  28. Didriksen

    Didriksen

    Joined:
    Aug 9, 2015
    Posts:
    4
    Hello, new user of Behavior Designer here. Seems like a great tool. I'm working on porting my existing AI behavior into tree form.

    I am curious about the Wait task, I can't get it to work. It doesn't seem to ever return success. Is it because I set my tree to repeat forever, or is it because of something else?

    I basically have a selector with two child tasks, one conditional checking if a target is within distance, and a wait task set to 4 seconds. So if the distance check fails, the selector should still return true after 4 seconds, if I'm not mistaken.

    Edit: I've gone through the source code for the Wait task, and I see that OnStart() and OnUpdate() is called every frame, but OnPause(), where the elapsed time is advanced, never gets called. I'd love to know what I'm doing wrong :)
     
    Last edited: Dec 5, 2018
  29. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    219
    Is the behavior designer integration for the legacy UFPS still available? Looking to download it but I can't seem to find it
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    For support can you post on the opsive forums at https://www.opsive.com/forum? This will allow me to track support requests better. It would be helpful if you also post an image of your tree.
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Version 1.6.1 of Behavior Designer is making its way to the Opsive Store and the Asset Store. This update adds support for assembly definition files so the files had to be restructured. As a result, ensure you remove the Behavior Designer directory before importing this update. If you are storing any files in the Behavior Designer directory you should first move them to prevent them from getting deleted.

    You can see the full change log on this page:

    https://opsive.com/news/behavior-designer-1-6-1-released/
     
  33. Brumby

    Brumby

    Joined:
    Sep 8, 2014
    Posts:
    16
    I have issue with External Behavior after update to Version 1.6.1. Nothing happen in Behavior Designer Window during the Play Mode. Please check the attached movie. Am I doing something wrong?
     

    Attached Files:

    Last edited: Dec 14, 2018
  34. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Thank you for letting me know - sorry this one slipped through. My unit tests didn't specifically test this since it was playing at runtime. I guess I need to create a new unit test :) The fix is now live on the store.
     
    Last edited: Dec 14, 2018
  35. spood

    spood

    Joined:
    Jun 9, 2015
    Posts:
    2
    After updating to Unity 2018.3.0f2 (and currently on Behavior Tree 1.6.1) I started getting an error when I select an object in the inspector that has a behavior tree component assigned to it. This behavior tree was created on the previous Unity version. As a result I can't view or modify the behavior tree on this object. The stack trace:

    Code (CSharp):
    1. InvalidCastException: Cannot cast from source type to destination type.
    2. BinaryDeserialization.BytesToSharedVariable (BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.Dictionary`2 fieldIndexMap, System.Byte[] bytes, Int32 dataPosition, IVariableSource variableSource, Boolean fromField, Int32 hashPrefix)
    3. BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource)
    4. BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource)
    5. BehaviorDesigner.Editor.GraphDesigner.Load (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, Boolean loadPrevBehavior, Vector2 nodePosition)
    6. BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, Boolean loadPrevBehavior, Boolean inspectorLoad)
    7. BehaviorDesigner.Editor.BehaviorDesignerWindow.ReloadPreviousBehavior ()
    8. BehaviorDesigner.Editor.BehaviorDesignerWindow.OnInspectorUpdate ()
    9. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
    10. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    11. System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
    12. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    13. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
    14. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
    15. UnityEditor.HostView.OnInspectorUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:211)
     
  36. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    For support please post on the opsive forum so I can track the requests better. There was also a recent thread which might help.
     
  37. spood

    spood

    Joined:
    Jun 9, 2015
    Posts:
    2
    No worries, I rolled to a previous commit, exported the behavior tree, then rolled back to the newest version and the exported tree works fine. Not sure what happened that caused it in the first place (I may have been playing around with the prefab, but didn't think I did anything that would cause problems), regardless I'm not having any problems now.
     
    opsive likes this.
  38. Rowlan

    Rowlan

    Joined:
    Aug 4, 2016
    Posts:
    1,114
    Is there an example / tutorial with animated characters?

    What I need is to add an enemy model with animations, define follow and combat animations. The AI should follow the player and attack the player as soon as the player is within reach. Is there some kind of wizard for that?
     
    Last edited: Dec 20, 2018
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    The best way to do this is to have the character controller manage the animation playback. Take a look at this page for more details:

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

    For any new support topics please post on the forum at https://opsive.com/forum so I can track the request better.
     
  40. kk99

    kk99

    Joined:
    Nov 5, 2013
    Posts:
    77
    hello, I have one quick question.

    Is it possible to re-use sequences in multiple trees?

    Lets say I have a sequence that moves the NPC to a target, the NPC picks up something from the ground, plays an animation and do some idle stuff

    I would like to reuse this sequence in another sequence? Is that possible?


    I used before Panda Behavior Tree and I could easily re-use trees here and there. Unfortunately, that Tool had various other issues so I had to switch. upload_2018-12-31_11-18-8.png
     
  41. kk99

    kk99

    Joined:
    Nov 5, 2013
    Posts:
    77

    my question has been answered https://www.opsive.com/forum/index.php?threads/re-use-sequences.565/#post-2794

    thanks
     
    opsive likes this.
  42. TheSwizzler

    TheSwizzler

    Joined:
    Aug 21, 2016
    Posts:
    5
    Has ECS been integrated into Behavior Designer yet? Seems that AI is a perfect place to implement the system (along with jobs of course)... :)
     
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    ECS is still in preview mode so it'll be awhile before it can be fully utilized. There are still a lot of systems that are not ECS/jobs supported yet so I'm waiting for ECS to become more mature. AI is a good candidate, but I still want to be allow for easy task creation so it may makes sense for BD to only support jobs and not ECS (which will still obviously give a nice speed boost).

    We have a smaller experimental asset that is following along with the ECS development so I can keep up to date with how it works. I imagine that we'll release this new pure ECS asset first, then update BD with our experiences from that. Unity is still figuring out how all of the ECS pieces fit together.
     
  44. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    146
    Why textfield copy/paste does not work on Variables tab?
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    If you can post on the support forum with steps to reproduce that would be great. I just tried to copy/paste and was able to.
     
  46. ben-britton

    ben-britton

    Joined:
    Feb 7, 2015
    Posts:
    12
    suggestion for a new movement for movement pack:
    Guide (or Lead): would move toward the player, and then guide the player to a designated destination (walk-toward (within eyesight of player) <destination (default=0,0,0)>, then wait for player (x seconds)), then repeat.
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    I think for that you should be able to use a combination of the Seek/Follow tasks combined with the Wait and Repeater tasks:)
     
  48. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    146
    Even in the variables name?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,750
    Thanks, I see it now. I was using the GUI version of TextField rather than the EditorGUI version of the TextField and that caused the events not to be sent. I've made the change and it works now - if you send me a PM with your invoice number and Unity version I can send you a fixed version before the next release.
     
  50. joaobsneto

    joaobsneto

    Joined:
    Dec 10, 2009
    Posts:
    146
    No worries, it's a little bit annoying to retype the variables name when using sub trees, but it's not blocking my work. I will wait the next release. Thanks!
     
unityunity