Search Unity

Behavior Designer - Behavior Trees for Everyone

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

  1. FiveFingerStudios

    FiveFingerStudios

    Joined:
    Apr 22, 2016
    Posts:
    359
    Will take a look...thanks!
     
  2. MarkusGod

    MarkusGod

    Joined:
    Jan 10, 2017
    Posts:
    164
    Hi, I was trying to implement kind of strafe movement with BD, but I can't find any rotate prevention in the movent pack, so I ended up with modifying class NavMeshMovement (added bool and set UpdateRotationin onStart instead of
    Code (CSharp):
    1. if (!updateRotation.Value) {
    2.                 UpdateRotation(true);
    (More correct should be to make custom movements)
    But can "strafe" be done without custom nodes, something like using evade and RotateTowards?



    Edit1: Ok, I just can set angular speed =0. :eek:
     
    Last edited: Nov 3, 2017
    opsive likes this.
  3. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    Greetings.. had this package for a while and just started to integrate it into my project with RFPS.

    Went smoothly until I added the integration file and then got a couple of errors...

    Severity Code Description Project File Line
    Error CS1061 'AIAgent' does not contain a definition for 'useMecanim' and no extension method 'useMecanim' accepting a first argument of type 'AIAgent' could be found (are you missing a using directive or an assembly reference?) rfps+gaia+enviro+BT.CSharp F:\Unity Projects\rfps+gaia+enviro+BT\Assets\Behavior Designer\Third Party\Realistic FPS Prefab\Tasks\Shoot.cs 31


    Any tips?

    M
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Thanks for heads up - I've updated the RFPS integration and sample scene. Once you import these new files you should no longer get a compiler error (the RFPS changes as before still need to be followed).
     
  5. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    Thanks for the high speed turnaround:) will see what I get :)


    M
     
    Last edited: Nov 21, 2017
  6. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    OK that worked fine thank you :) Now am trying to get Dialogue System integrated.

    Integration went fine.. no issues, no warnings.

    So I tried the basic Hello World conversation. I have a conversation and have setup the Behaviour tree (I believe exactly as shown in the docs).
    However.. the wait never releases to the Start Conversation. If I remove the wait task.. and just have the Start Conversation, I get hello world at the top of the screen which fades after about a second or two.. however if I put the wait back.. My tree lights up green onto the wait task, but the wait never releases.

    Again, I am sure its simple and me, but if you have any ideas I would appreciate it.

    M
     
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Glad you got it working. What does your tree look like?
     
  8. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    Morning :)

    okay pic attatched...

    convo.jpg

    M
     
  9. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    That tree is about as basic as you get :) So Wait is never ending and is staying lit up green? How long do you have the duration set for? This shouldn't matter, but if you place an Idle task instead of the Start Dialogue task does it change anything?
     
  10. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    Yep very simple to try and get used to everything working together.

    Yep Wait goes green and never changes from that.

    Placing an Idle didn't change anything.. Wait went green and stayed there as with Start Convo.

    Heres the inspector settings I have on wait.

    convo2.jpg

    All I have in this project are RFPS, Behaviour Trees and Dialogue with all the interfaces setup. No console errors anywhere.. on unity 2017.1.2f1

    M
     
  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Here's a scene with a similar setup as that tree. Can you modify this scene so it shows a similar behavior as what you are seeing? It sounds like something else is going on.
     

    Attached Files:

  12. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    Yep that locked on wait and never progressed as well :)

    The zip of the project is 271k. If you like I could send the whole thing :)

    M
     
  13. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Did you try my scene in a fresh project? If that still doesn't work feel free to send an email to support@opsive.com so I can take a look at the entire project.
     
  14. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    OK new project, added the scene, added behavior trees, worked fine no issues.. waited one sec and then moved to idle.

    confused I am :)

    M
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Progress :) It looks like something is interfering with that tree. I would import RFPS and then the Dialogue System one by one to see if you can get the issue to occur again in the new project.
     
  16. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    OK as you say progress..

    I have save files at every stage of setup so reloaded my project with just RFPS and BD with integration files added and the changes done to the scripts and loaded your scene and the wait locked up again.

    So I guess that eliminates Dialogue:)

    M
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    The only thing that would affect the Wait task in the scene that I sent is if you have a different time scale. Ensure you have a timescale of 1. If that still doesn't work try copying over all of the project settings from the project which works to your existing project. RFPS is in the complete projects section of the Asset Store so by default it'll replace all of your project settings.
     
  18. moria15

    moria15

    Joined:
    Feb 25, 2011
    Posts:
    390
    OK a hero you are :)

    I did some digging and searching and discovered that apparently, RFPS starts with Timescale 0 until the scene has loaded with the RFPS player in it.. it then resets to 1.

    So I added a script to my convo item that in start sets the timescale to 1 and it works and now fires the convo.

    I guess this is very specific to RFPS and I got caught by it.

    Anyway, thank you so much and for all the responses.

    Now onto the next :)

    Regards

    M
     
    opsive likes this.
  19. lorddanger

    lorddanger

    Joined:
    Aug 8, 2015
    Posts:
    72
    Hello,
    Is there any changelog. so that its easy to check what is changed, Updated, fixed , added with each new version
     
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Yes - there is a release notes pdf updated with each release under the Behavior Designer directory.
     
  21. henjo

    henjo

    Joined:
    Nov 10, 2014
    Posts:
    1
    Hi,
    I have one behavior tree for the leader where target is specified, the followers are using different behaviour tree(s) where leader is specified. If leader dies, first follower should be leader with target and the rest should follow this object instead. What is best practice to achieve this?
     
  22. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    When the leader dies the task for all of the followers will also end. You can then create a task to determine who should be the next leader. I do this in the Deathmatch AI Kit within the team tree. The Should Lead Search/Find Leader tasks will determine the new leader. Unfortunately there isn't a way to automate this more with a task included within the Formations/Tactical Pack because it's very game specific on who you want to be the next leader.
     
  23. IdleUser

    IdleUser

    Joined:
    Dec 2, 2017
    Posts:
    3
    BehaviorScreenshot.png Third Person Shooter AI-Scene.PNG Hi,
    I have 4 errors in behavior inspector. can't replace or locate new task with right click.
    I have installed movment and tactical pack. And this error i have in the Third Person Shooter AI Scene.
    In the Unity Inspector i miss a script!
    what can i do to fix it.

    pleas look the screenshot...

    thanks for reply
    Peace
     
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    With the Third Person Controller sample scene you'll need to make sure you have the Third Person Controller integration as well as the Movement Pack imported. Take a look at this page for how that tree works:

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

    IdleUser

    Joined:
    Dec 2, 2017
    Posts:
    3
    Thanks for the link! i have read the whole article, but i don't understand how to intergrate.
    Do have to script somthing? hmmm...pleas help.
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Yes, you'll need the Third Person Controller integration found on the Behavior Designer samples page:

    http://www.opsive.com/assets/BehaviorDesigner/samples.php

    The sample scene also requires the Movement Pack.
     
  27. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    I have a scene with many points of interest (buildings) and tourist info booths. There are also several tourists with behavior tree components attached. The tourist would go to the nearest info booth and receive a Transform for the next building to visit. The next building is selected by some C# function inside an info booth component. After visiting the building, the tourist finds another nearest info booth and the process repeats.

    I'm new to BD, so my question is pretty basic. What is the best way for the tourist BT to receive target Transform of the info booth?
     
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Are you spawning the tourist or are they already in the scene? If they are already in the scene you could create a SharedTransform and just assign that SharedTransform within the editor. If not you'll need to do something like this:

    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=137
     
  29. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Just to clarify, everything in the scene is dynamic. For example, tourists will be spawned at random times and move between multiple info booths and buildings. Also, the info booths will direct different tourists to different buildings based on the current game state and tourist data (such as the list of previously visited buildings).
     
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    You'll want to go with the Referencing Scene Objects route then. You'll want to populate the SharedVariable with the object after they have been spawned.
     
  31. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Thank you! That helped. I also found some ideas in the RTS sample.

    More questions :)
    1) What is the best way to copy BT to another project? I tried exporting BT to an asset, but it opened in the new project with many tasks shown as "Unknown" even though I have both Behavior Designer and BD Movement in this project. For example, "Seek" shows "Unknown Seek" with a "!" in red circle.

    2) Is there a task that finds the closest object with a given tag?
     
  32. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    That method should work - you'll want to make sure you have the Movement Pack imported into the project before you open up the tree. The tree deserializes based on class path so as long as you have the tasks imported it'll find a reference to it.

    Within distance can use a tag and will returned the first object found that is within distance, but it isn't guaranteed to be the closest.
     
  33. username132323232

    username132323232

    Joined:
    Dec 9, 2014
    Posts:
    439
    Turns out I also needed the RTS sample :)

    That's what I'm currently using. An option to return the closest object would be nice though.
     
    Last edited: Dec 11, 2017
  34. blacksun666

    blacksun666

    Joined:
    Dec 17, 2015
    Posts:
    158
    Is there a way to use behavoir designer to generate a repeatable cutscene type arrangement. Basically I'd like to have two teams of bots fight it out (thinking of getting the deathmatch AI kit if it helps) but I'd like to trigger this as an cut scene and control the camera to cut between parts of the scene I think are interesting. Ideally I'd be able to generate new scenes in the editor until I find one that has what I'm looking for and then somehow save the seed or something so I can recall it again later once I've automated my camera.
    Is this possible? If so how?
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    The primary purpose of behavior trees aren't a cutscene tool so for something like that I personally would recommend Unity's new Timeline and Cinemachine system. Beyond that you could use the Sequence task to iterate from one task to another. If you do end up going the behavior tree route you'll likely need to create some custom tasks to control the camera cuts.
     
  36. adhdchris

    adhdchris

    Joined:
    Nov 13, 2013
    Posts:
    45
    Hey opsive,

    I've been trying to pool external behavior trees by following the example in the docs, however, ExternalBehavior does not contain the Init() method anymore. Is there another way I can preload and deserialize external behavior trees to prevent GC at runtime? Thanks!
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Make sure you are using Behavior Designer 1.5.11 - the init method was added to the last release.
     
  38. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    Is there a problem with Bolt integration?


    In your sample scene you have this. After I run the scene, the "MyIntVariable" still remains to 7 even that Bolt is doing that math so the variable is actually becoming 42.

    However, no errors. In my scene I'm trying to get the Object Variables from my Prefab and I'm getting this:

    Also... question. Target Game Object. If I set it to None, does it know to "Get Self"? How can I specify "self"? I also get the error if I set the Target Game Object to None.

    Another question. In order for a variable to sync, I need to have the Variables in Bolt, but I also have to manually create them in BD ... right?

    Thanks!

    EDIT: I created a new GameObject. I added a simple Flow with 2 variables (a String and a Float). Then I'm trying to use the Sync Variables Action. No errors if I don't create the variables in BD. If I create the Variables in BD, I start to get the same error. I know this might be something super basic that I'm doing wrong ... but I'm new to BD and I'm still trying to get my head around it.
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Thanks for the heads up. It looks like internally Bolt now represents an int as a float so that was causing the problem. I've updated the integration files so the variables now synchronize.

    If you leave the target field as blank (with no SharedVariable) then it'll reference itself. A SharedVariable value of None will give an error since that is pointing to a null object.

    That's correct
     
    GamerPET likes this.
  40. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    Now it works. The only downside is that ... it's doing this the other way around :D

    Like when I syncronize the variables, BD is setting his variables to Bold, and I wanted it the other way around. I want Bolt to send his variables to BD :D
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Are you using the Start Flow Graph task? When this task starts it'll synchronize the variables from Behavior Designer to Bolt, and then when it'll end it'll synchronize the variables from Bolt to Behavior Designer. With the Playmaker integration there is an explicit task which allows for this synchronization and I could add something similar for Bolt if it's not in the order that you want it in.
     
  42. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367

    I'm trying to learn how the system is working. So right now I have that "Seek" with the speed value of 0.

    Bolt has a Float variable called "speed" with the value of 1. I created in BD another value called "speed" with the value of 0 (default value).

    I expected that when I start that "Start Flow Graph" (I also tired it with Sync Variables) Bolt is going to set the "speed" variable to BD, then the Seek task will start ... with that new Speed value.

    I mainly want to use Bolt to do my heavy stuff, because there I can calculate values, run For Eaches in order to get a target, etc etc. I mainly want BD to do it's Tree stuff.

    It will be awesome if you could make it so Bolt sends variables to BD.

    I'm also not really sure but my 2nd Sequence is not triggering. It supposed the "Has Received Event" to trigger, since I'm sending that event from Bolt, but it never fires. This is the Bolt graph right now:



    -------------
    I'm trying to see if I can learn this so I can create some Tutorials. I already did some Bolt tutorials. There is a huge cap in tutorials when it comes to BD (and Bolt).

    For example, right now I'm having a simple AI made form State Machines. But I want something a bit more complex. Like I want my "archer" to shoot, check for a new target to shoot then... just in case some Enemy is coming close to him, I want him to retreat.

    With State Machines this would be a bit challenging because I might have to add the "retreat" checkup in multiple states. I think that maybe I can acomplish this better with BD.

    Like Bolt doing the heavy lifting with calculations, instantiating stuff from the object pool, etc... and BD setting up some tasks that are gonna be send to Bolt.

    Again, no idea how to do this optimally yet.

    P.S. Merry Christmassssss!!
     
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Ah, so what is happening is that when Behavior Designer starts it'll send it's speed value of 0 to Bolt so Bolt now has a value of 0. When Start Flow Graph ends since the variable was synchronized to 0 it'll get sent back to Behavior Designer with a value of 0. The fix for this case would be to set the speed value to 1. Having a task which allows for manual synchronization that you place before Start Flow Graph would also help if you don't want to set the value to 1 in Behavior Designer.

    edit: I just looked and it looks like there already is a Synchronize Variables task. With this task you can synchronize variables from Behavior Designer to Bolt, which you'd do at the start of the tree.

    Awesome - looking forward to it :)

    Merry Christmas :)
     
  44. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    Yea but that Synhronize Variables task is doing the same thing. BD is sending his variables to Bolt. I want it the other way around. I want Bolt to send the variables to BD.
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    I just updated the integration package to be able to allow you to select which direction to send the variable. Here's the updated task:

    Code (csharp):
    1.  
    2.     public class SyncornizeVariables : Action
    3.     {
    4.         [Tooltip("The GameObject which has the FlowGraph attached to it.")]
    5.         public SharedGameObject targetGameObject;
    6.         [Tooltip("Should the tree's variables be synchronized with Bolt's Variable component?")]
    7.         public SharedBool synchronizeVariables;
    8.         [Tooltip("Should the global variables be synchronized with Bolt's Variable component?")]
    9.         public SharedBool synchronizeGlobalVariables;
    10.         [Tooltip("Should the variables be synchronized to Bolt?")]
    11.         public SharedBool synchronizeToBolt = true;
    12.  
    13.         private GameObject target;
    14.         private GameObject prevTarget;
    15.         private Variables boltVariables;
    16.  
    17.         public override void OnStart()
    18.         {
    19.             target = GetDefaultGameObject(targetGameObject.Value);
    20.             if (target != prevTarget) {
    21.                 boltVariables = target.GetComponent<Variables>();
    22.                 prevTarget = target;
    23.             }
    24.         }
    25.         public override TaskStatus OnUpdate()
    26.         {
    27.             if (synchronizeVariables.Value) {
    28.                 BehaviorDesignerExtensions.SyncVariables(boltVariables, Owner, synchronizeToBolt.Value, false);
    29.             }
    30.             if (synchronizeGlobalVariables.Value) {
    31.                 BehaviorDesignerExtensions.SyncVariables(boltVariables, Owner, synchronizeToBolt.Value, true);
    32.             }
    33.  
    34.             return TaskStatus.Success;
    35.         }
    36.     }
    37.  
    38.  
     
    GamerPET likes this.
  46. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    With this new script, if I uncheck the "Syncronize to Bolt", that Object reference error is back.

    If I check it, no error but I get that old behaviour (BD to Bolt).

    I checked to see, both of my variables are Floats.
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    What is the error? The line numbers would be different because of my update. I just tried it in the sample scene and it worked:

    Bolt.PNG
     
  48. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    I'm also trying onthe sample scene. No errors there but my "string" variable from Bolt doesn't seem to match.

    Here is a short video:

    https://streamable.com/2zage

    From my main scene, this is the error that I'm getting:
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,683
    Thanks for working with me on this. I haven't gotten extensive feedback on the Bolt integration so it's good to flush out these issues. I've uploaded a new version of the integration files - once you download that version it should synchronize strings.
     
  50. GamerPET

    GamerPET

    Joined:
    Dec 25, 2013
    Posts:
    367
    Thanks. Now it seems to work!

    A couple of more questions. I'm using the Seek action. Is there a way to specify the "forward" vector (or however it's called) for the unit that is moving? I positioned my unit the way I want, but the moment it starts moving, BD places it with the vector up. I would like the "Up" of the unit to not be on the Y axis, but on the X.



    I have this small graph.
    This is the BD:


    I think I might know why but ...

    Start Flow Graph triggers the "Fight" (from bolt).
    Has Received Event should get triggered from Bolt, with that event "eventFromBolt". But it's not doing it.

    That 2nd Sequence does nothing. My guess is that ... since the 1st Sequence has not finished, the 2nd Sequence is not active to receive that event from Bolt.

    Right?

    Anyway, thanks for the integration.
     
    Last edited: Dec 25, 2017