Search Unity

Behavior Designer - Behavior Trees for Everyone

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

  1. lorddanger

    lorddanger

    Joined:
    Aug 8, 2015
    Posts:
    103
    Hello ,
    I have being playing the BD.on The BT I have a SharedGameObjectList and some other as well
    From external script (PlayerController.cs)
    If some something is not a List then I can set the Values with SetVarible
    but How do Add / Remove a from List ie SharedGameObjectList etc ????
     
  2. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The Value property will give you access to the actual SharedVariable value. For example:

    mySharedGameObjectList.Value.Add(myGameObject);

    This page has more info:

    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=54
     
  3. Teila

    Teila

    Joined:
    Jan 13, 2013
    Posts:
    6,932
    Do you still have the integration sample with Motion Controller? I cannot find it on the integration/sample page at all although you direct me to it in the discussion about using MC with BD.
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Unfortunately the Motion Controller sample project no longer exists - it was created by ootii for Motion Controller version 1 and was never updated for version 2.
     
  5. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    how do I zoom in/out in the behavior designer window without a mouse? Could you add zoom buttons somewhere? Perhaps right click on the board then zoomin/zoomout option in the dropdown.
    Working on a laptop without a mouse I have set 'Mouse wheel scrolls graph view' for faster orientation around the board but cannot zoom in any way now. Have to disable it (but it really improves the navigation around the board with a mac trackpad)
     
  6. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    If the mouse wheel scroll preference is enabled you can hold the command key to zoom. This should allow you to zoom without a mouse :)
     
  7. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    would you be able to add a conditional evaluator for layers?
     
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I'm not following - which layers are you referring to?
     
  9. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    Unity layers. Theres get and set layer actions, so right now you need to store the layer as a string variable to compare it. This could be one step with a conditional that would compare the layer of the target gameobject against a specified layer.
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Ah, so a new conditional task. Yeah, it would look something like:

    Code (csharp):
    1.  
    2.         public SharedGameObject targetGameObject;
    3.         public LayerMask layermask;
    4.  
    5.         public override TaskStatus OnUpdate()
    6.         {
    7.             return (GetDefaultGameObject(targetGameObject.Value).layer & layermask.value) != 0 ? TaskStatus.Success : TaskStatus.Failure;
    8.         }
    9.  
    I'll include this task in the next version.
     
  11. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    I've been seeing the following error a lot lately. It just spams my console only when I have the Behavior Tree Editor open and have the character selected so it has something to do with the behavior tree editor window. I also think it may have something to do with the gameobject character with the behavior tree being a prefab clone in the scene. Once the error starts, my tree is basically corrupted since I can't make the error stop spamming.

    The only way I can make the error go away that I've found so far is to delete the character prefab in the scene and drag a new clone into the scene. Luckily I've been able to catch this error before Applying any changes I've made to my character prefab. Because my biggest fear is I end up corrupting the behavior tree on the prefab itself instead of just the clone of the prefab in my scene.

    I have Allow Edit of Prefab Instances selected in the preferences but somehow things are still getting corrupted.

    KeyNotFoundException: The given key was not present in the dictionary.
    System.Collections.Generic.Dictionary`2[BehaviorDesigner.Runtime.Behavior,BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree].get_Item (BehaviorDesigner.Runtime.Behavior key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
    BehaviorDesigner.Runtime.BehaviorManager.GetTaskList (BehaviorDesigner.Runtime.Behavior behavior)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateNodeTaskMap ()
    BehaviorDesigner.Editor.BehaviorDesignerWindow.OnInspectorUpdate ()
    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)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    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)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:272)
    UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:265)
    UnityEditor.HostView.OnInspectorUpdate () (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:164)

    Thanks
    Allan
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Are you able to reliably reproduce that error in a project that you can either send me or list how I can reproduce it? This error is being thrown because the Behavior Tree doesn't exist in an editor dictionary that it should exist in.
     
  13. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    416
    Justin.

    Sorry for the delay on this. I haven't been able to figure out how to reproduce it. It's a tough one because it just seems to happen for no reason. So far all I can say is it has only occurred when I'm working on a character with a Behavior Tree that exists as a prefab instance in the scene. I'm trying to get in the habit of breaking the prefab instance any time I start to work on my Trees. So far I have not seen the error as long as the prefab instance is broken.

    But I'll keep trying to track it down.

    Allan
     
  14. mcmonk

    mcmonk

    Joined:
    Sep 22, 2014
    Posts:
    14
    Hey!

    I'm new to behavior designer and want to do a turn based behavior tree. I managed to create a "turn started" by modifying the "wait for event" conditional. Is there a common/best way of making sure that the sequence after the "turn started" runs per event fire. So i want to fire "do one thing" then wait for another "turn started" event fire and then run "do another thing" etc. This might be a basic question but again, i'm new to the behavior syntax.

    BehaviorScreenshot.png
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Do you only want to run a single task after Turn Started returns success, or do you want to run a group of tasks? If you want to run a group of tasks your tree looks correct - when Turn Started returns success it'll run all three action tasks because of the parent sequence task. As your tree grows you'll probably want to use some conditional aborts to control the flow but that's definitely a good start.
     
  16. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352
    what is the best way to save the state of a behavior tree during runtime (just variables)?
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You could loop through all of the variables with behaviorTree.GetVariable, and then when you want to revert the value you can use behaviorTree.SetVariable. This page has more explanation on the API within the behavior tree:

    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=43
     
  18. rasto61

    rasto61

    Joined:
    Nov 1, 2015
    Posts:
    352

    thats pretty much what im doing and then storing that as a json string, but is there no way to get the json representation of the variables from BD directly ?
     
  19. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Yes - the serialization is stored within the BehaviorTree.BehaviourSource.TaskSerializationData.JSONSerialization. You could then parse this string to only contain the variables list. On the Deserialization side of things it expects the entire behavior tree serialization data but there is a JSONDeserialization.DeserializeVariables private method that you could expose.
     
  20. mcmonk

    mcmonk

    Joined:
    Sep 22, 2014
    Posts:
    14
    I want to run them each indiviudally after a turn started event has fired. So "turn started" returns true -> then the first thing happens -> "turn started" -> second thing -> etc. I have tried to rearrange the states to do this like this:
    BehaviorScreenshot2.png

    But this just prints: "turn start" -> 1, 2, 3-> "turn start" -> 1, 2,3,4 -> "turn start" -> 1, 2,3,4 -> "turn start" -> 1, 2,3,4
    It never stops to wait for a event at the second "wait for turn started" conditional?

    My code is:

    Code (CSharp):
    1. namespace BehaviorDesigner.Runtime.Tasks
    2. {
    3.     [TaskDescription("Returns success as soon as the player initiated a turn.")]
    4.     [TaskIcon("{SkinColor}HasReceivedEventIcon.png")]
    5.     public class TurnStarted : Conditional
    6.     {
    7.  
    8.         private bool eventReceived = false;
    9.         private bool registered = false;
    10.  
    11.         public override void OnStart()
    12.         {
    13.             // Let the behavior tree know that we are interested in receiving the event specified
    14.             if (!registered) {
    15.                 turnInfo.turnStarted += turnStartedEventFire;
    16.                 registered = true;
    17.             }
    18.         }
    19.  
    20.         public override TaskStatus OnUpdate()
    21.         {
    22.             return eventReceived ? TaskStatus.Success : TaskStatus.Failure;
    23.         }
    24.  
    25.         public override void OnEnd()
    26.         {
    27.             /*
    28.             if (eventReceived) {
    29.                 turnInfo.turnStarted -= turnStartedEventFire;
    30.                 registered = false;
    31.             }
    32.             */
    33.    
    34.             eventReceived = false;
    35.         }
    36.  
    37.         private void turnStartedEventFire()
    38.         {
    39.             // BEHAVIOUR TREE SHOULD MOVE ON HERE!
    40.             //Debug.Log("Turn started");
    41.             eventReceived = true;
    42.         }
    43.  
    44.         public override void OnBehaviorComplete()
    45.         {
    46.             // Stop receiving the event when the behavior tree is deactivated
    47.             turnInfo.turnStarted -= turnStartedEventFire;
    48.  
    49.             eventReceived = false;
    50.             registered = false;
    51.         }
    52.  
    53.         public override void OnReset()
    54.         {
    55.             // Reset the properties back to their original values
    56.         }
    57.  
    58.     }
    59. }
     
  21. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    With that tree setup the tree will end after each tick because no task returns a "Running" status. You'll instead want to setup your tree like:

    BehaviorScreenshot.png

    The Lower Priority Conditional Abort will reevaluate the Turn Started task so the conditional task can trigger when the idle task is active.
     
  22. mcmonk

    mcmonk

    Joined:
    Sep 22, 2014
    Posts:
    14
    Cool! I will try that. Thank you for the quick response!
     
  23. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    I get these errors ever since moving to 2017.1

    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'BehaviorInspector' could not be found (are you missing a using directive or an assembly reference?) MyProject.Editor G:\My Projects\2017.1.0f3\MyProject\Assets\Behavior Designer\Editor\BehaviorTreeInspector.cs 7 Active
    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'CustomObjectDrawerAttribute' could not be found (are you missing a using directive or an assembly reference?) MyProject.Editor G:\My Projects\2017.1.0f3\MyProject\Assets\Behavior Designer\Editor\Object Drawers\FloatSliderDrawer.cs 8 Active

    Any ideas on how to fix it?
     
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    It looks like it can find some editor classes. I would completely delete and then reimport from the Asset Store to ensure you have all of the files.
     
  25. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    168
    Hello, I was looking through Final IK integration sample and there some error in example scene.
    Набросок.png
    But most things working fine. But I still can't figure out was is this value should be referenced to.
     
  26. LootlabGames

    LootlabGames

    Joined:
    Nov 21, 2014
    Posts:
    343
    I have done that and still getting the error.
    I did a search for the 'BehaviorInspector' class and didn't find one with that name.
     
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Thanks for the heads up. I've updated the FinalIK tasks and sample scene so that error will no longer appear. FBBIKLimb was looking for a GameObject that has the FinalIK components attached but if it's left blank then it'll use the current GameObject (which is why the sample still worked).
     
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    BehaviorInspector is contained within BehaviorDesignerEditor.dll. Do you have that file? Can you list the steps to reproduce the error from a fresh 2017.1 project?
     
  29. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    168
    Thanks for so fast response and fix! Here another integration problem with Unistorm.
    upload_2017-9-4_19-2-2.png
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The UniStorm integration has been updated :)
     
    MarkusGod likes this.
  31. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    214
    Will projects made incorporating behavior designer and the other opsive adons work on console platforms like the playstation ps4 and xbox one?
     
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Yes, they will :)
     
    blacksun666 likes this.
  33. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Hey Guys,

    Just a question, im relatively new to unity. I just purchased Behaviour Designer from the asset store for later, when i need to create AI for my enemies (zombies, monsters, men etc) in my VR game. However, i then also came across the A* Pathfinding Project Pro and saw that its currently on 50% sale.

    So basically my question is if i already got Behaviour Designer, will that be enough for me and i dont need the other AI asset? or do i still require the A* asset to work with Behaviour Designer to create AI for my enemies?

    Please if someone could advice that would be really helpful! Thanks
     
  34. RobsonFMaciel

    RobsonFMaciel

    Joined:
    Jan 12, 2013
    Posts:
    187
    I would like to know how Behavior Designer behaves with my already written codes, is it possible to integrate? If I have codes ready, can I access them through the Behavior Designer interface?
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Behavior Designer and the A* Pathfinding Project implement different AI techniques so they can complement each other. Behavior Designer is a behavior tree implementation while the A* Pathfinding Project is a pathfinding implementation. The Movement Pack can use the A* Pathfinding Project to move the agent from one point to another.

    Hopefully that helps!
     
  36. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    You definitely can use existing code. Take a look at this page for writing a new task:

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

    You could also use the reflection tasks if you don't want to write any code but by writing your own task you get a significant speed increase and flexibility.
     
    RobsonFMaciel likes this.
  37. RobsonFMaciel

    RobsonFMaciel

    Joined:
    Jan 12, 2013
    Posts:
    187
    Amazing, thank you :D
     
    opsive likes this.
  38. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Hi there, I just bought behavior designer and wish to use it to make vivid AI for various animals in my game.
    But I got a bit knocked off while learning it, doesn't find many tutorials out there, and don't know where to look in the documentations for specific needs.
    So here I am, trying to make a simple fish AI that wanders under water surface and above terrain.
    When the water gets shallow it knows to return to deep water and flee from players or other creatures from enemy factions when they are heard or in sight.
    Don't know where to start or if I can achieve this with built in tasks (I have movement pack too). Or should I write my own movement task especially for fishes or birds that can move on Y axis?
    PS: about the hearing task, how do I set the target's noise range? Or it is automatically calculated by the audio source's range?
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The Behavior Designer videos page is great for Behavior Designer specific features, while the Deathmatch AI Kit page has links to more general behavior tree structure resources.

    I've been asked this a few times so I just created a topic for the Movement Pack docs.

    On the task you can set the range that the target will hear. The audibility threshold will determine the volume that the sound needs to emit in order for the task to trigger.
     
  40. Harekelas

    Harekelas

    Joined:
    Feb 3, 2015
    Posts:
    864
    Thanks for the links! I'll go check them out!
     
  41. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    @opsive If you don't mind me asking I saw this plugin was on sale this week, and I was wondering what the difference between this and A* Pathfinding Project is? I was interested in getting a plugin for AI in my 2D game at some point, but am somewhat new to the subject of AI.
     
  42. opsive

    opsive

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

    Behavior Designer and the A* Pathfinding Project implement different AI techniques so they can complement each other. Behavior Designer is a behavior tree implementation while the A* Pathfinding Project is a pathfinding implementation. The Movement Pack can use the A* Pathfinding Project to move the agent from one point to another.
     
  43. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Hey, thank you for your reply. But i just need some more information on this to make a decision.

    You said both are different AI techniques, but can you get by (without compromise) on just using Behaviour Designer? or is A* a big requirement?

    The AI that i have mostly in my game is zombies, standing/walking around, who only move towards the player on sight and noise. Plus some other creatures who do the same but also maybe on smell aswell.

    Then i also have a few more Human Like enemy who actually chase the player, around the house, through a woods etc... these AI would actually move and search for the player around the level using sight and noise.

    So for my enemies in my game am i able to just use Behaviour Designer? or would i definitely be required to also have the A* Pathfinding asset?

    Lastly, i heard that there is a free version also of the A* Pathfinding asset that is just missing one feature from the paid version. But if you say that A* Pathfinding asset is required for my game and its AI described above, would you say that the free version of A* Pathfinding asset is more then enough or that the paid version would really be required?

    Thanks for your help!
     
  44. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Behavior Designer doesn't require the A* Pathfinding Project in any way. The A* Pathfinding Project is integrated with the Movement Pack so if you'd like to use the A* Pathfinding Project for pathfinding you definitely can. With that said Unity has a built in pathfinding solution called the NavMesh and the default implementation of the Movement Pack uses Unity's NavMesh.

    You will definitely need some sort of pathfinding, whether it is Unity's NavMesh system or the A* Pathfinding Project. Behavior Designer doesn't actually move the agents around the scene - rather it can help make the decision that the agent should move around the scene. It is then up to to underlying pathfinding implementation to do the actual movement.

    I would take a look at the A* Free vs Pro feature comparison page to decide if you're interested in any of the pro features.

    Does that clear it up at all?
     
  45. KillerNads

    KillerNads

    Joined:
    Jan 22, 2017
    Posts:
    70
    Ah cool, thank you i think i understand now! Yeah thats what i was really confused about, is if your not using A* then i thought you were using your own. I didn't realise you were using Unity's NavMesh system. I guess A* is a lot better then NavMesh so i should probably use that for my enemies. I had a look at the differences between free and pro. I guess the main difference is the live calculations of the environment that can change, so good if its non-static.

    I guess i should just get A* Pro to use with this as its 50% off right now and might never be again in the future :D

    Thanks for your help
     
  46. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Are there plans for Bolt (Visual Scripting) integration?
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Bolt has been on my radar and I generally do the integrations based on the popularity of the asset as well as the number of requests that I receive... Is anybody else interested in Bolt integration?
     
    red2blue likes this.
  48. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Bolt support would be very nice!!

    Is there any way to use Behavior Designer with Bolt in the meantime?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I haven't used Bolt yet so it's tough to say but if it's similar to the Playmaker integration then it'll probably take a couple of integration tasks to do correctly. With the Playmaker integration the Behavior Designer task can start and stop the FSM along with getting a return value and updating the variables. Some of that may be possible with Bolt depending on the API but I don't think reflection can cover all of the use cases.
     
  50. DeepShader

    DeepShader

    Joined:
    May 29, 2009
    Posts:
    682
    Ok, so I've to wait for a maybe-integration and can't use it with Bolt before?