Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Behavior Designer - Behavior Trees for Everyone

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

  1. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    250
    @opsive Can you set icon path relative ?
    Because I never leave plugin at project root and so icons are never load.
    It's not big deal but that can be a help visually
     
  2. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    385
    There seems to be a bug with the Tactical Pack, specifically the LeapFrog behavior. If you run the included demo scene, and get to leapfrog, the first time it works fine. but if you go backward or forward to another behavior, and then back to Leapfrog, it fails every time. The agents get into formation and then just sit there. This concerns me because Nothing I've tried will fix it without restarting the scene, and I don't want this kind of freezing happening in my game.
     
  3. Kusras

    Kusras

    Joined:
    Jul 9, 2015
    Posts:
    129

    Hi today I just opened Behavior Designer window and it starts throwing issues. I worked in that few hours before that issue and closed project normally next time I am unable to edit trees - any trees, even empty window does not work. I tried to restart unity, did not help, tried to revert to factory settings did not helped :( I am lost, do you have an idea what to do. It seems like any editor issue... because trees are working, just cannot be displayed or edited
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    That's a good idea - I'll get it in the next release. We're releasing v2 of our character controllers and I plan on spending some quality time with BD :)
     
    Sylmerria likes this.
  5. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Make sure you're using the latest version of Behavior Designer on the Asset Store.
     
  6. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Good catch. This related to the leader tree unsubscribing from events because the behavior tree ended with the task switch. Open Leapfrog.cs and change AddAgentToGroup to:

    Code (csharp):
    1.  
    2.             base.AddAgentToGroup(agent, index);
    3.  
    4.             if (leader.Value == null) {
    5.                 if (index < agentReady.Count) {
    6.                     agentReady[index] = false;
    7.                 } else {
    8.                     agentReady.Add(false);
    9.                 }
    10.             }
    11.  
     
    ceebeee likes this.
  7. Kusras

    Kusras

    Joined:
    Jul 9, 2015
    Posts:
    129
    @opsive thanks it work sorry I forgot to check if there is any patch...
     
  8. ceebeee

    ceebeee

    Joined:
    Mar 7, 2017
    Posts:
    385
    Nice, that fixed. it. :)
     
  9. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    27
    Hello, I just started using the asset, and I can't figure out how to do a behavior.

    I wish my AI to seek a location, in the meanwhile, if the player gets close to it, the AI will try to evade the player while keep seeking the location. So something like a weighted motor, like if the AI's target is positive x but the player is also in its positive x direction (which means the AI needs to run towards the negative x), and if I can give the seek a weight of 70% and give the evade a weight of 30%, the AI can still move towards positive x direction instead of gets stucked.
     
  10. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Hey, having issues using Has Entered Trigger and Has Entered Collision. Can't get it to work for the life of me. I even added a Debug.Log to be thrown on trigger enter if the tag matches. Not getting anything in response. Both objects have colliders, both have rigidbodies, have tried every variation of isTrigger being enabled on each. Not getting anything
     

    Attached Files:

  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    You'll want to make use of conditional aborts in this situation. Your tree would start out by looking similar to this tree:



    On the left you'd have Within Distance reevaluating every frame. Immediately after Within Distance you'd have a custom conditional task that checks the player direction and random weighted number, and then based off of that you'd either seek or evade. Take a look at this page for a more complete example:

    https://opsive.com/support/document...er/integrations/opsive-character-controllers/
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    It doesn't look like your trigger is being reevaluated. Take a look at this post for an example:

    http://legacy.opsive.com/forum/index.php/topic,135.0.html
     
  13. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    27
    Thanks! I'll let you know when I try this out.
     
  14. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Hello!

    Would anyone have a clue why my behavior gets stuck on this repeater node?

    When the int comparison fails at the end of the tree, the pursue sequence (just above) should repeat itself but the repeater node above the sequence is stuck and doesnt repeat anything.

    upload_2018-9-18_20-51-32.png
     
  15. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Here are the settings of that stuck repeater node:
    upload_2018-9-18_20-52-50.png
     
  16. loliconest

    loliconest

    Joined:
    Sep 21, 2015
    Posts:
    27
    This should be an easy question but I can't find a tutorial about this:

    When I use a "Stop Behavior Tree" and tick the "Pause Behavior" checkbox, and when my behavior is paused, how can I use another behavior tree to resume it?

    I have another question: how can I set the values for individual tasks? For example, there is a "Random Float" task, which returns a random float between a min and a max value. How can I set the min value and max value beside fill them manually?

    I also want to know how robust is the build in random generator, like if I have a "Wander" task in the tree, will my agent go to the same direction everytime I start? Or it will be random each time?
     
  17. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,039
    The Mini-Gauntlet Sample Project seems not available anymore. I'm trying to link Mecanim and behaviour trees. Anyone have another source on how to do that?
     
  18. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Hmm.. it shouldn't matter but as a test can you remove the Parallel task to see if that helps at all?
     
  19. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    You can use the Start Behavior Tree task to resume a behavior tree. The Behavior Game Object field specifies which GameObject you want the task to operate on.

    Take a look at this page:

    https://opsive.com/support/document...es/accessing-variables-from-non-task-objects/

    Wander uses Random.insideUnitSphere in order to determine the next position so it will be random if you don't use a seed.
     
    loliconest likes this.
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Tom163 likes this.
  21. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Hi, small question, I was reordering some variables in the editor and everything became real slow, eventually unity froze and I had to crash and restart it.

    Anyone else has this problem? Is there anything I may be doing that could be slowing the editor to a crawl?

    UPDATE: Been getting these errors since restarting unity, check the 2nd post bellow for screen shots (doesnt let me upload in an edit)
     
    Last edited: Sep 21, 2018
  22. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Thank you, actually solved my problem by readoing the whole branch differently. Would have been nice to understand the problem but it works now so, til next time!
     
  23. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    The first two errors are the same:
    error1.PNG

    And here is the 3rd error:
    error2.PNG

    W'ere on Unity 2017.4.3f1
     
  24. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    All my nodes are gone!!!

    All i was doing was rename a variable and reorder some... OMG

    How do I fix this?

    UDAPTE:

    My External behavior tree file is empty! How can this happen!?

    Its unaceptable you have to rewrite how you handle your asset files, this just CANT HAPPEN!

    I am so pissed off right now.
     
    Last edited: Sep 21, 2018
  25. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Can you send me a repro scene or tell me how to reproduce the error? If you are updating from a version prior to version 1.5.7 you'll need to reserialize before hand but besides that I haven't recently had any reports similar to this.
     
  26. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    I am not updating anything, I was just moving variables around under the variable, the more i moved them the solwer unity got but by the time I realized what was going on the whole thing was frozen.

    Had to terminate unity, when I realoaded the project I found that my external behavior tree was now an empty text file.
     
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    I'm sorry that happened. Do you have a backup? I really haven't had reports of anything like this before and I would love to know how to reproduce it so I can ensure it doesn't happen again.

    In the next update I will be using a reorderable list for the variables tab so that should make things a bit quicker instead of having to draw all of the EditorGUILayout fields. I can send you a prerelease version of this if you'd like as soon as I get it done (probably sometime next week).
     
  28. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    I have just spent the last 4 hours trying to fix unity... after trying all the shenanigans I could find only one thing fixed unity.

    Moving the Behavior Designer folder out of my project.

    I will try to reintegrate it shortly.

    Now... reguarding the external behavior tree file that got erased during a crash... How about ALLWAYS making a backup before writting to them? I would rather erase uneeded backup files than loose this amount of work again.
     
  29. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Omg... it wont let me load the messed up file or the version I restored from my last working commit...
    I cant drag them to the external behavior tree box and if i click the circle beside it to "browse" for the file instead its EMPTY!
     
    Last edited: Sep 28, 2018
  30. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    If your original working file is corrupted it sounds like there was a larger data failure with your hard drive. I wish that I was able to help more but hopefully you have been taking regular backups.
     
  31. tcz8

    tcz8

    Joined:
    Aug 20, 2015
    Posts:
    235
    Hi, it wasnt my hard drive. Its really something that slowed down the editor to a crash while I was workign in the BD editor on an external behavior file. Sorry for freaking out the other day btw. Had it rough last week. Thank god I sent my collegue a screenshot of the finished tree just before. Was much faster to redo my work.

    Thanks for your support.
     
  32. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Just have kind of a general question for you. Is there a good way to setup a behavior tree to follow a simple if else tree of states? Maybe an example somewhere?
    Basically most of my AI behavior I'm looking to execute like so
    Code (CSharp):
    1. if(thing1)
    2. {
    3.    execute actions
    4. } else if(thing2 is true)
    5. {
    6.     execute actions
    7. } else if (thing3 is true)
    8. {
    9.     execute actions
    10. } else
    11. {
    12.     execute actions
    13. }
    Basically I just want to setup a tree so if one of the "things" is true it will stop pursuing if another has priority. I know I should do this with condtional aborts, but I'm still having some trouble fully understanding how these work. I think I'm particularly having a hard time wrapping my head around the concept of how these aborts work when dealing with deeper trees. I seem to wind up just setting almost all Sequence nodes to "lower priority" aborts to ensure that if there's a lower priority abort near the root of the tree, this gets overridden. However, I imagine having all these conditional aborts is not ideal in terms of performance?

    I typically just code things but have been trying to get past my bigotry of more node based visual systems because I know it's particularly useful for AI. Any articles or resources you have to help provide clarity or to help ease a programmer in to a tool like this would be much appreciated :p

    I don't know why I have such a hard time grappling with more visual forms of scripting lol
     
  33. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Conditional aborts are definitely the way to go. Have you seen this video? It gives a pretty good walkthrough of this situation:

    Code (csharp):
    1.  
    2. if (can see object) {
    3.    Seek;
    4. } else {
    5.    Idle;
    6. }
    7.  
     
    DespairBear likes this.
  34. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    99
    Am I not allowed to register to the forum when I have not purchased Behavior Designer ?
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    The opsive forums are for support requests so it requires an invoice. If you have a pre-purchase question you can post it here or send it to support@opsive.com
     
  36. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    262
    Hello, i created a script that gets called from a behavior tree to deal damage to the networked player the enemy is attacking. I had it working fine but just revisited the project due to time restraints and Unity is stating it doesn't like the script. if i dont touch it and run the game it works but unity is stating it needs to derive from a misbehavior to be added as a component to the enemy. This is the Action code:
    Code (CSharp):
    1. using UnityEngine;
    2. using BehaviorDesigner.Runtime;
    3. using BehaviorDesigner.Runtime.Tasks;
    4. using BattleMayhem;
    5.  
    6. public class EnemyAttackPlayerTask : Action
    7. {
    8.     public SharedGameObject _target;
    9.     GameObject _player;
    10.     public float MinDamageToDeal = 5;
    11.     public float MaxDamageToDeal = 15;
    12.     bool Played = false;
    13.  
    14.     public override void OnStart()
    15.     {
    16.         base.OnStart();
    17.         var DamageToDeal = Random.Range(MinDamageToDeal, MaxDamageToDeal);
    18.         _player = _target.Value as GameObject;
    19.         PlayerStats stats = _player.GetComponentInParent<PlayerStats>();
    20.         stats.TakeDamage(DamageToDeal);
    21.         Debug.Log("dealing damage to Player: " + _player.name);
    22.     }
    23. }
    It looks ok and doesn't throw any error from what i can see.

    If someone could let me know what i am doing wrong if they can spot something would be great.

    This is the error Unity is now giving to the previously ok script.


    https://imgur.com/a/ln8UIuW

    Any help greatly appreciated.

    Thanks

    Daniel
     
  37. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Hey kind of a combo question regarding Behavior Designer Movement and UFPS. I noticed that if I use the A* integrated movement and I apply it to a unit with any collider, if the unit wanders into my enemy it kind of pushes the UFPS player for a second but then the UFPS player winds up moving inside of the AI unit. This is probably a common problem and I'm curious as to how to solve this issue.
     
  38. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Tasks are not MonoBehaviours so you can't add them as components. You'll only be able to add it to the behavior tree.
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Are you using version 1 or 2 of UFPS? Version 1 uses Unity's Character Controller component and doesn't have as strict of control over the locomotion aspect. You shouldn't be having this problem in version 2.
     
  40. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    I'm using version 1 still. I'm looking at upgrading to v2, but my project currently utilizes Dialogue System and I'm not sure if out of the box support is done yet? I'm also a little short on cash right now. I would like the Ultimate Character Controller but I can't fully justify the price point being I have both Third Person and UFPS 1 haha. Maybe in the next couple months though.

    Anyone else experienced this issue and have a fix?
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Tony from Pixel Crushers almost has the integration done :) When you are able to upgrade a lot of the popular integrations should be complete.
     
  42. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Awesome, I'll look into that asap. I guess I'll hold off on developing the character mechanics and just focus on the central parts of the AI until then :p keeps me on track I suppose
     
    opsive likes this.
  43. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    262
    cool thanks, i'll give it a try and let you know how i get on, thanks
     
  44. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Got a simple question for you. So I have a script that sends off an event to the parent's behavior tree, and I am trying to utilize a sequence in the parent that looks like this:
    HasReceivedEvent.PNG

    I figured this would work, and I have verified that the event is firing off from the script to the appropriate object, but it doesn't ever seem to return success. Below is a snippet of the code that is sending the behavior to the tree

    Code (CSharp):
    1.                    
    2. var behaviorTree = GetComponentInParent<BehaviorDesigner.Runtime.BehaviorTree>();
    3. Debug.Log("sent message to " + behaviorTree.gameObject.name);
    4. behaviorTree.SendEvent<GameObject>("MemberDied", gameObject);
    I guess my main question would be, in order for the Has Received Event node to work properly, would I have to use the Send Message node within a behavior tree, or should sending it to this behavior tree from within a script like this still operate as expected?
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    Your tree is ending before the event has a chance to be received. If you parent that branch with a selector and then have an idle task as the second child of the selector it should then work.
     
    DespairBear likes this.
  46. DespairBear

    DespairBear

    Joined:
    Nov 1, 2013
    Posts:
    215
    Having the tree repeat itself on completion wouldn't work for this? Obviously it doesn't but I'm curious as to why

    Thanks for the help
     
  47. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
    No - when Has Received Event ends it unsubscribes from the event so the gap between the tree ending and starting again causes the event to be missed.
     
    DespairBear likes this.
  48. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    99
    What I need is full determinism. I need to call BT update whenever I want and also task updates when I want. I don't want to use unity3d Update method. Is it possible with Behavior Designer and how. Could you point me to some documentation ?
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,701
  50. mcmorry

    mcmorry

    Joined:
    Dec 2, 2012
    Posts:
    579
    I implemented two new nodes, SmoothDamp and SmoothDampAngle, but I need to execute the logic in the LateUpdate as I'm using them to move a camera.
    The issue is that the LateUpdate method is never executed.

    Here is the code:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityVector3
    4. {
    5.     [TaskCategory("Basic/Vector3")]
    6.     [TaskDescription("Move from the current position to the target position by a smooth acceleration and deceleration.")]
    7.     public class SmoothDamp : Action
    8.     {
    9.         [Tooltip("The current position")]
    10.         public SharedVector3 currentPosition;
    11.         [Tooltip("The target position")]
    12.         public SharedVector3 targetPosition;
    13.         [Tooltip("The time to reach the target position")]
    14.         public SharedFloat smoothTime;
    15.         [Tooltip("The damp result")]
    16.         [RequiredField]
    17.         public SharedVector3 storeResult;
    18.  
    19.         Vector3 _currentDumpVelocity;
    20.  
    21.         public override void OnStart()
    22.         {
    23.             _currentDumpVelocity = Vector3.zero;
    24.         }
    25.  
    26.         public override void OnLateUpdate()
    27.         {
    28.             base.OnLateUpdate();
    29.             Debug.Log("SmoothDamp.LateUpdate()");
    30.             storeResult.Value = Vector3.SmoothDamp(currentPosition.Value, targetPosition.Value, ref _currentDumpVelocity, smoothTime.Value);
    31.         }
    32.  
    33.         public override void OnReset()
    34.         {
    35.             currentPosition = targetPosition = storeResult = _currentDumpVelocity = Vector3.zero;
    36.         }
    37.     }
    38. }