Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AI: Behaviour trees in Unity: Behave 1.1 released

Discussion in 'Assets and Asset Store' started by AngryAnt, Sep 29, 2010.

  1. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Please note the earlier answers in this thread.

    Unity still has an unsolved bug where its internal compiler is trying to execute gmcs at the wrong path. The workaround for now is to install the mono runtime on your system as mono will fall back to the standard gmcs path if the one specified doesn't work.
     
  2. BrUnO-XaVIeR

    BrUnO-XaVIeR

    Joined:
    Dec 6, 2010
    Posts:
    1,687
  3. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    568
    I had the same problem months ago. Martin solved it for me. Here is his solution from earlier in this thread:

    Hi,

    this looks like a mac problem. This doesn't happens under Win.

    I found sone articles about this problems:

    - https://github.com/AngryAnt/Behave-release/issues/21
    - http://www.tech-recipes.com/rx/2621/...ment_variable/

    I don't know how to store environment variables permanent so open the Terminal and enter:

    export PATH=$PATH:/Applications/Unity/Unity.app/Contents/Frameworks/Mono/bin
    open /Applications/Unity/Unity.app/
    now you can compile the tree




    CU
    Martin
     
  4. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    Thanks for the help, I should've looked to see if someone already answered my question before asking.

    Right now I'm have an error that says 'BLNewBehaveLibrary0' does not contain a definition for ' instantiate tree'.
    This time I checked the thread to if someone already answered it I promise.

    Here's the part of the code that seems to be causing the problem:

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using System.Collections;
    5. using BehaveLibrary;
    6. using Behave.Runtime;
    7. using Tree = Behave.Runtime.Tree;
    8.  
    9. public class NewBehave : MonoBehaviour , IAgent {
    10.  
    11.     Tree m_Tree ;
    12.    
    13.     IEnumerator Start ()
    14.     {  
    15.         m_Tree = BLNewBehaveLibrary0.InstatiateTree (BLNewBehaveLibrary0.TreeType.NewCollection1_NewTree1,this);
    16.         }
    17. }
    18.  
    19.  
    Fixed:
    It was brought to my attention that I had spelled Instantiate wrong (missing n).
     
    Last edited: Jul 7, 2012
  5. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    Do we know of somekind of problem working with Behave 1.4 and Unity3d 3.5.3f3?

    I'm trying out the basic code AA used in his video...I see no errors. No "ticks" in the debug.log though.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using Behave.Runtime;
    5. using Tree = Behave.Runtime.Tree;
    6.  
    7. public class AgentAwesome : MonoBehaviour, IAgent
    8.  
    9. {
    10.     Tree m_Tree;
    11.    
    12.     // Use this for initialization
    13.     IEnumerator Start () {
    14.    
    15.         m_Tree = BLTryAgain.InstantiateTree(BLTryAgain.TreeType.DoomsdayCollection_AwesomeTree  , this);
    16.        
    17.         while (Application.isPlaying  m_Tree != null)
    18.         {
    19.             yield return new WaitForSeconds (1.0f / m_Tree.Frequency);
    20.             AIUpdate();
    21.         }
    22.    
    23.     }
    24.    
    25.     void AIUpdate ()
    26.     {
    27.         m_Tree.Tick();
    28.        
    29.        
    30.     }
    31.    
    32.     public BehaveResult Tick (Tree sender, bool init)
    33.     {
    34.         //Debug.Log("sender: "+sender);
    35.         Debug.Log("Got ticked");
    36.         return BehaveResult.Success;
    37.     }
    38.    
    39.     public void Reset (Tree sender)
    40.     {
    41.        
    42.     }
    43.    
    44.     public int SelectTopPriority (Tree sender, params int[] IDs)
    45.     {
    46.         return IDs[0];
    47.     }
    48.    
    49.    
    50.    
    51. }
    52.  
    This is what i get in the console:

    And no errors.

    Wierd.
     
  6. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    I see this in the editor log.

    Is it normal for the C0T0 to be appended to the library name?

    I have a feeling that may be where this problem is arising.
     
  7. gl33mer

    gl33mer

    Joined:
    May 24, 2010
    Posts:
    281
    I've seen the post regarding the priority output showing up differently than in the video (text is vertically aligned) - But there is also another difference. The output connections don't show up the way they do in the video. They only show for each individual output when you press the little box not when the priority selector is selected and all outputs show like they do in the video.

    hmm...
     
  8. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    I was having this exact problem, so I went back to the behave tutorial and copied the code exactly as well as the tree. The console is still only show Got Ticked three times.


    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using BehaveLibrary;
    5. using Behave.Runtime;
    6. using Tree = Behave.Runtime.Tree;
    7.  
    8. public class NewBehave1 : MonoBehaviour , IAgent {
    9.  
    10.     Tree m_Tree ;
    11.  
    12.    
    13.     IEnumerator Start ()
    14.     {  
    15.         m_Tree = BLNewBehaveLibrary0.InstantiateTree (
    16.             BLNewBehaveLibrary0.TreeType.NewCollection1_NewTree2,
    17.             this
    18.         );
    19.        
    20.        
    21.        
    22.         while (Application.isPlaying  m_Tree != null)
    23.         {  
    24.             yield return new WaitForSeconds (1.0f / m_Tree.Frequency);
    25.             AIUpdate ();
    26.         }
    27.     }
    28.        
    29.     void AIUpdate ()
    30.     {
    31.         m_Tree.Tick ();
    32.     }
    33.    
    34.     public BehaveResult Tick (Tree sender, bool init)
    35.     {
    36.         Debug.Log ("Got Ticked");
    37.        
    38.         return BehaveResult.Success;
    39.     }
    40.    
    41.    
    42.     public void Reset (Tree sender)
    43.     {
    44.        
    45.     }
    46.    
    47.    
    48.     public int SelectTopPriority (Tree sender, params int[] IDs)
    49.     {
    50.         return IDs[0];
    51.     }
    52. }
    53.  
    http://i.imgur.com/PPsxy.png
     
  9. TianWolf

    TianWolf

    Joined:
    Aug 20, 2011
    Posts:
    161
    Does anyone have experience using Behave with a pathfinding solution? If so, which one, and how well did it work for you?
     
  10. Leiter Jakab

    Leiter Jakab

    Joined:
    Sep 25, 2010
    Posts:
    53
    I use Behave with the A* Project by Aron Granberg. It works perfectly and I don't see any reason why it shouldn't work with any solution. I simply call the pathfinding function from the tick function of an Action.
     
  11. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    Hi I'm totally new to all this. Why does an IAgent implement the code for actions? What if I want reusable actions among different agents? I thought each action is a class.

    Here's a screenshot of a game I'm more or less taking the idea from:


    If you code that as a behavior tree, it'd be really simple (not that I'd design my tree that way). Clearly the conditions would be common to all agents, however the actions an agent has can differ (only someone who learned heal spell can heal. here, unit HAS-A spell).

    From what I understand of AngryAnt's video, the actions are coded into the IAgent. Either that's a lot of if's or a switch statement to execute the proper attack/spell, or I store them into a Dictionary, or I use handlers. And they all sound like a lot of duplicate code. Obviously I'm missing something here.
     
  12. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Does anyone have any suggestions when dealing with a large number of agents?

    I have found that with my tree tick frequency at 1 second, and with around 30 agents running at once, that my framerate completely tanks every time the tree ticks. I know its the behavior tree causing this because it happens every time the tree ticks.

    The actual code being executed by these agents is simple, and was actually running incredibly smoothly prior to implementing it using the behavior trees.

    My tree is below. As you can see, its a fairly short and simple tree. The agent simply goes into a wander behavior whenever the target is not spotted. When it is, it checks their distance, if they are within attack range, they continue attacking until that is false. When it's false, the agent then moves onto the chase action, which continues to run until the target either runs out of vision range, or the agent gets within attack range.

    I tick my trees using the method described a few pages ago, with the basic tree setup for C# (start the AI tick coroutine at Start, tick it 1f/tree frequency)

    $Behave Issue.PNG
     
  13. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    So I created a function that throttles behavior tree ticks. Works fine. Now I can have 100 agents ticking behavior trees at once.

    However I have also found out that sometimes randomly, Behavior Tree ticks are triggering a really nasty effect. When a lot of agents are ticking, Something is causing my Character Controller agents to fall clean through the terrain/objects they are standing on.

    They fall through because they have gravity applied to them (downward Y direction on their Move functions during Update). The problem here is that the tree ticking is causing some funkyness with the Unity collisions. If I set my tree frequency to 0, everything is fine.

    Not too thrilled, I've spent a good week chasing this thing down, since its a pretty major problem. Anyone have any suggestions?
     
    Last edited: Aug 9, 2012
  14. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I hit a similar problem to this in Unity but without Behave, the problem was triggered when the characters transitioned between two collision layers, in my case the land and sea and I introduced code to allow the characters to swim. The problem was at the edge of the land and see it was possible for vertical movements to push the character through the collision layer and then sink under it as though they had entered quick sand.

    So check to see if the falling through problem is happening at joins or when the character is being driven through the terrain. I have also encountered problems like this performance problems and the physics of the game starts lagging behind, in effect objects are moving too fast for collisions to register.

    Changing the collision types settings can reduce or eliminate this problem.

    Also you could add code to your characters that ensure they are not all thinking on the same tick, e.g. only allow some to update every x ticks (this could be status dependent).

    Hope that helps.
     
  15. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Hey Arowx,

    I have indeed created a function that limits the updates per frame for each AI agent. I basically keep a count of agents and tick them all 2 - 5 at a time, if any others try to tick at this point I tell them to wait to skip that tick and wait for next one.

    This works great actually, I have 100 agents able to operate using individual behavior trees at the same time.

    The problem is this: Both my Player and AI Agent character controller scripts have gravity applied to their move scripts on the Update function. I'm not at home so I can't post code, but essentially every update I apply a -9.8 movement to the character controller's Move function, so an Agent or the Player's every move looks something like controller.Move(X, y - 9.8, Z)

    The thing stumping me is that this has been working fine as is for months. Agents and the player can move up and down slopes and terrain without falling through. It wasn't until I introduced this ticking that this started happening. I completely agree that I think this is being caused by the stuttering, and somehow Unity is missing the collider check or something, during some of the ticks. And since gravity is applied every update, if a single tick causes the colliders between terrain and characters to hiccup, they will fall clean through the floor.

    I don't have any layers in particular, or any sort of switching. They're plain character controller components with a downward movement applied every update. I even tried moving their move functions (and the gravity) inside the FixedUpdate block instead of update, but I got the same results, to my frustration.

    Regarding the collision type settings, you mean the layers?

    PS: this issue also happens when the player is standing completely still. The way I test is I introduce a lot of ticks and then I sit still and wait to see if I fall through the floor. It takes a few minutes of waiting and ticking with 100 agents, but as you may imagine, falling clean through the floor is a pretty unacceptable bug to leave uncorrected :-/
     
    Last edited: Aug 9, 2012
  16. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Just wondering why you are applying gravity when character controllers respond to the default gravity settings applied in physics?

    You could assign your characters a rigidbody and collider then at least you have the capacity to change the collision detection settings.
     
  17. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    A Character Controller by default, does not fall downward unless you apply a constant downward direction to their Move method. I believe SimpleMove does, but I do not use it as I want complete control over my characters.

    Rigidbody + collider isn't an option since they are character controllers and you can't mix and match both.

    I'm now fairly convinced this is some sort of physics glitch... I'm just not having very much luck figuring out what's triggering it. What sucks is that it happens so randomly, I hate it, spent a few days trying to fix this already. I'm also sure its not an issue with the character controllers themselves as other unrelated rigidbodies fall through the floor when this happens as well.
     
  18. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    @AnomalusUndrdog
    Yea that sounds like a bad idea. What you could do is add some actions used as conditions - giving the tree information about which spells or other actions are available. You can then use those in your tree design to pick viable actions.

    @Rico21745
    As mentioned on twitter I highly doubt that Behave itself is causing your performance problems or your physics issues. Rather I suspect it is the way you use Behave. The code generated by Behave is nothing but a bunch of switches and ifs - ultimately calling your code.

    If you have pro I would suggest firing up the profiler to figure out if things are really called the way you expect them to. Otherwise I would start seeding my action handlers with log messages to do the same.
     
  19. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    You can you just add a sub-object with a rigidbody but you create a joint that can produce strange behaviours.

    Try upping the physics time steps.
     
  20. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Hey Angryant,

    I agree, I don't think it's Behave, I thought it may have been because it started as soon as I introduced Behave into the equation, but I believe now that the issue may be tied to physics somehow. Maybe in low FPS situations, the physics misses the collision between controller and terrain, causing them to go clean through :-/

    No Unity Pro license sadly, so I can't access the profiler. I know the behavior tree is ticking properly as I did in fact use log messages to try the logic. The AI works great now, aside from this issue, which is slowly eating away at my soul.

    @Arowx:

    Yup, I tried upping that to 0.1 from 0.2 but still had the same issue. I may try to go extremely low just to test some more but that may not be a feasible solution due to performance issues caused by setting it too low.
     
  21. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    @Rico21745

    I would suggest taking the issue to a new thread in the scripting section and posting the link here. Given that the problem now seems a bit off-topic and you're likely to have more luck through more eyeballs on a new thread.
     
  22. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Will do, I know this isn't the right place for this issue anymore.

    Regarding Behave, version 1.4 is from quite a while ago. Any idea when a new version may be coming down the pipe?

    Is there any sort of community wiki or more documentation available? I know my biggest issue was figuring it all out since docs are a bit sparse, and I only managed from reading this entire thread, but I'd say there's got to be a better way than reading 16 pages :)
     
  23. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    I'm working on both a new site and new versions of Behave. Unfortunately I'm very busy at work these days, so things are not exactly moving at blitzing speeds. :)
     
  24. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    Is it possible to create reusable decorators? That is I need "Do not execute more often than X seconds" decorator. However I don't want to implement it in every agent, moreover I need several of these decorators simultaneously in one tree.

    So in general: is there any way to create custom decorators and define what they will return and how?
     
  25. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,551
    The way I see it, you'll have to put your code for that decorator in a separate class, then let your agents instantiate that class every time it needs such a thing.
     
  26. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    This is a bit sad, however maybe the only solution for the problem at the moment.
     
  27. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    That seems a bit strange and drastic? Though a viable solution, sure. It all depends on what makes sense for your particular case.

    What I would do is define a base agent class which implements virtual handlers for a number of common decorators and actions.

    Then deriving all your agents from that class will transparently give you that functionality and you still get to override the handler for custom cases. This is essentially what agent blueprints do.
     
  28. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    I thought about inheriting all agents from the base class, however I can't see how it'll help me when I need two (or more) decorators at the same time in one tree, at least not in easy way. As far as I understand the information should be inside the decorator itself, not in an agent.

    That is, if I have two "not often that X sec" decorators in a tree, I don't need to implement TWO timers (or instantiate some class or whatever), I just drop the decorator in a tree, it works as a filter and updates on its own, so I can just write it once and then forget about how it works, letting designers just to use it anywhere.
     
  29. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Devast3d:

    I think what AngryAnt said would actually work, just make sure you name any decorators that you want to share that behavior the exact same as the original one.

    IE: Decorator "CheckSight" should be implemented in your base IAgent class, then any classes that inherit from it will automatically be able to use it. Simply place a new decorator on your tree, and name it the same.

    In fact, I think I may end up doing this tonight, since I finally have my base agent class and my behavior tree "behaving" after a lot of headaches, heh.

    I'll let you know how I end up doing it tonight, if you like.

    @Angryant:

    I noticed a lot of Behave components have a checkbox for "Instant" which I couldn't find a description for in-editor, or on the Behave docs. Could you shed any light on this checkbox by any chance? Since trees are ticked manually through code, it definitely cannot have anything to do with ticking the tree, could it?
     
  30. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    I understood the approach of subclassing from the base class and line of sight "check" will work, because it does not have any information associated with it, in contrast timer decorator has the data (actual time, float) and that data is UNIQUE across the decorators, putting the timer Init/Tick/Reset methods into the parent agent class will give me one timer, of course I can duplicate the timer instances and name them differently (eg Timer1, Timer2...), or make some sort of collection which will be queried by the parameter of the decorator in the editor (float or string), but this looks more of a hack to me..

    So basically I want to share the way decorators work not the data they store.
     
  31. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    @devast3d:
    To have for instance multiple timers in the same tree, use the decorator string parameter to differentiate. You could then use the float parameter to indicate the timer duration.

    Also note that you can pass any data object to your initial Tree.Tick call. This object is passed as a parameter to all handlers, meaning you can either store data in it or access data from it for evaluation in your handlers.

    @Rico21745:
    The instant flag is used by output components such as sequences and selectors.

    Normally when a sequence ticks a child and that child returns success, the sequence advances its child index and returns running - waiting for the next tick. However if the child was marked as instant, the sequence just advances its child index and immediately ticks the next child.

    This is especially useful for actions used as simple logic conditions - IE "has ammo" or "is healthy" - so you don't spend a whole tick on just checking those values one at a time.
     
  32. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Why don't you keep whatever timer you need in your base class, then if you need to override the number, do it in the child class?

    IE: I have a timer to check LOS in my base agent class that uses a variable "checkTime" to determine how often to check LOS. Now I create a "SuperDetector" agent that checks LOS more often. The approach I would take, is simply to initialize this same variable with a different number.

    At the same time, nothing is stopping me from using that same Decorator for other things like "CheckForWeapons", as long as the behavior I want out of the decorator matches my initial design of "Perform X every Y seconds". In that case, you simply may want to make your decorator sound more generic and call it "CheckAfterSeconds" and rename your timer to something more appropriate like "checkFrequency".

    In your tree then, I'd imagine you can use the data you can store in your decorator component to have the designers be able to specify the timer value for whatever they want (using the float), then you simply grab that data in your decorator implementation and assign it to your "checkFrequency" variable when that Decorator is ticked.


    @Angryant:

    That sound incredibly useful, I'm glad I asked about it, since its actually something I'm doing quite frequently! Thanks!
     
    Last edited: Aug 15, 2012
  33. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    I'm in urgent need of dynamic selector (i.e. selector which checks for the priority every tick and interrupts any running child). As inspector help says current Priority Selector does not recheck priority on the next tick if some child is running already. Any help with this?

    --

    I'm also struggling with Parallel node. If I want to use it alongside with some assertions (like in Alex video on aigamedev.com), by no any means I want for all children to be executed if I found that one of my assertions fail. For example, if I have active target and want to do something with it (probably during several ticks), I don't want to execute "DO SOMETHING" child if "TARGET IS AVAILABLE" child has returned failure. Theoretically I would create parallel node with first child doing assertion and second child doing something, then I expect the parallel node to fail when one (the first) of its children fails and then immediately bail out of the node, NOT running the action which uses the target which is already unavailable!

    And two cents about decorators. It would also be neat to have customizable logic for them, as now they are hardly usable in many cases. I need decorator which in case of successful ticking runs its child and pops the result (as it does now), however I need it to return FAILURE if it tick fails, but right now it'll return success.
     
    Last edited: Aug 16, 2012
  34. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    Regarding your urgent need for a dynamic selector - could you describe the use case?

    With regards to the parallel node, this sounds like an excellent use case for a decorator.

    Re: Decorators: Yep. As mentioned earlier in this thread, I am well aware of the limitations of the current decorator design and will be releasing a new design later :)
     
  35. devast3d

    devast3d

    Joined:
    May 30, 2010
    Posts:
    76
    imagine simple combat selector with 3 child nodes:
    • retreat
    • attack
    • alert
    any of these children could return all 3 BehaviorResult's, here I'm emphasizing Running state. And if previous tree tick had running attack, current tick might prefer retreating due to low health, however attack will continue running. Same problem with alert state, I don't want to contunie staring at enemy when I must aggro or retreat.
    Take into consideration that these behaviours are complex and may contain couple of checks before actual action occurs.

    Thanks for helping by the way.
     
  36. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    This is what decorators are meant for. Specifically for intercepting Running states. Alternatively, as you mentioned earlier, parallels can be used to interrupt as well.
     
  37. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    This is what decorators are meant for. Specifically for intercepting Running states. Alternatively, as you mentioned earlier, parallels can be used to interrupt as well.
     
  38. nuverian

    nuverian

    Joined:
    Oct 3, 2011
    Posts:
    2,087
    Your 2 video tutorials on your website seem to be down or something. Can I see them somewhere else?

    Thanks a lot
     
  39. r3david

    r3david

    Joined:
    Jul 3, 2012
    Posts:
    5
    I got multiple Enemies with the same behavior tree, and I want to know: is it possible to have actions of one of the enemies instances to depend upon actions on other enemies instances? For example, I want two enemies to pursue a target but in a way that they are aware of each other behavior or path etc..., so they don´t behave exactly the same. is this possible without using multiple behavior trees? and what would be the best approach using the Behave plugin? cheers! great tool :)
     
  40. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    @nuverian:
    Thanks. I'll give it a look and get them up again :)

    @r3david:
    Regarding best approach, that is a really tough question to answer, given the abstract nature of the tool. I would sift through these pages and see how others are using it and get some inspiration from them.

    When it comes to sharing information between agents, that really depends on your design. Classically you would use what's called a blackboard to share information. It's basically a fancy name for a big bag of tagged data which multiple entities can read from and write to.

    Implementations vary a lot as, again, they're very design / case dependent. Googling the term or looking through aiGameDev.com should yield some results though.
     
  41. r3david

    r3david

    Joined:
    Jul 3, 2012
    Posts:
    5
    @AngryAnt Thanks for the answer, I am googling right now for the blackboard" multi-agent system design. Have you thought of implementing that into a future release of Behave, or as another separate plugin? Cheers!
     
  42. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    I could perhaps do it as a separate thing. When I get some time at some point, y'know ;)
     
  43. olivier_henley

    olivier_henley

    Joined:
    Aug 14, 2012
    Posts:
    7
    Hi to all,

    Is there a way to execute some code on the entry and exit for a given tree?
    Even if this tree is only referenced through the instantiated root tree?

    Thx,
     
  44. Rico21745

    Rico21745

    Joined:
    Apr 25, 2012
    Posts:
    409
    Did you try using two decorators on your behavior trees? One called Entry one Exit. You can then use these decorators on any tree you create so long as you're inheriting from some base class that implements them (or you could rewrite the method for each of your agents, up to you).
     
  45. olivier_henley

    olivier_henley

    Joined:
    Aug 14, 2012
    Posts:
    7
    You mean two decorators plugged in series with the tree?
    You would control their symmetric execution with some control variables global to the tree or the base class?

    Just want to make sure I am not missing any clever way to proceed.

    Thx Rico!
     
  46. kebrus

    kebrus

    Joined:
    Oct 10, 2011
    Posts:
    415
    hi everyone, sorry if this has been asked before but..

    lets assume a simple action that commands the begging of a task, for instance, an action that starts the task of going from point A to point B

    this task shouldn't be handled by behave because of the tick rate versus the update function. so i'm guessing i would have to turn something on or off to make the object do the task in the update function. the thing is, sometimes it would be easier and faster to just know what action is currently being handled by behave in the update function, but i can't seem to find how to do it unless i save some information somewhere...

    i'm kinda confused, i admit i'm still adjusting to this way of doing AI so i might be thinking completely wrong here, but anyway i guess my question is, how should i handle the task itself? (not talking about handling the action, i mean the task)

    EDIT: i guess i found out myself, i just don't see it as been very effective, in a way is not much different as implementing my own loops and conditions... in fact, the way decorators work boggles my mind, it's so unintuitive, every time i want to create a simple condition i have to create a bunch of decorators and handle them... i really don't see the point of them working as interrupts or loops
     
    Last edited: Nov 8, 2012
  47. joessu

    joessu

    Joined:
    Nov 16, 2010
    Posts:
    88
    I have been spending a good week on behavior trees for my game, and behave is awesome!

    I am a bit confused about the best design pattern inside the SelectTopPrioriy(...) method.

    First of all, how do i determine what priority selector i am at (is it really just the range of IDs?), and ...

    If i return a priority and that branch fails and returns, i need to select another, but how do i know that previous branch failed? Of course i could figure this out by saving these states in my agents "metadata" support class, but that seems like it should be part of the Behave API.

    I have yet to see a intelligently implemented SelectTopPriority Method.
     
    Last edited: Nov 21, 2012
  48. MitchStan

    MitchStan

    Joined:
    Feb 26, 2007
    Posts:
    568
    Can someone give me some guidance on the best way to use SelectTopProirity. The way I have it set up currently works just fine. I'm using an If/Else code:

    Code (csharp):
    1.     function SelectTopPriority (sender : Behave.Runtime.Tree, IDs : int[]) : int
    2.     {      
    3.         if (diagnostics.Alert)
    4.             return BLBehaveWarehouse.PriorityType.Diagnostics;
    5.         if (group)
    6.             return BLBehaveWarehouse.PriorityType.Task;
    7.         else
    8.             return BLBehaveWarehouse.PriorityType.Idle;
    9.     }
    10.  
    And all is good. (I'm using unityScript BTW, not C#)

    But as I expand the capabilities of my behavior tree and add more priorities, the If/Else will begin to grow. I'm not too concerned because it works fine, but it occurs to me that there is a better way to do this without resorting to IF/ELSE.

    Can I just for instance, determine the top priority as part of an action? Like so:

    Code (csharp):
    1.     function TickNeedsPowerAction (sender : Behave.Runtime.Tree)
    2.     {
    3.         if (diagnostics.LowBattery)
    4.         {
    5.           /* SelectTopPriority = LowBattery*/
    6.             return BehaveResult.Success;           
    7.         }
    8.         else
    9.             return BehaveResult.Failure;
    10.     }
    And then in the SelectTopPriority Action just call the priority:

    Code (csharp):
    1.     function SelectTopPriority (sender : Behave.Runtime.Tree, IDs : int[]) : int
    2.     {      
    3.         /* return BLBehaveWarehouse.PriorityType; */
    4.     }
    Is something like this possible? If so, what would be the proper syntax for the lines of code that I commented out? I would just like to avoid a long IF/ELSE ladder.

    Any help on this would be much appreciated. This thread has gone quiet for such a great FREE AI library!

    Mitch
     
  49. lzt120

    lzt120

    Joined:
    Apr 13, 2010
    Posts:
    93
    After see the tutorial from http://arges-systems.com and here attach the project can works for behave 1.4

    My question is: Must it have a lot of bool varible for controling the action flow? In the proejct, there is four sequences and need three bool varible for controling the action flow. What if I have one hundred sequence action ? I need hundred bool varible ??
     

    Attached Files:

  50. AngryAnt

    AngryAnt

    Keyboard Operator

    Joined:
    Oct 25, 2005
    Posts:
    3,045
    For determining which priority selector invoked SelectTopPriority, you can set and check the current tree context.

    In the long run, the idea is to implement named priority selectors with separate handlers - like actions have them.

    @lzt120:
    Behave does not dictate which state data you should store in order to properly respond to action handler invokes. That is completely up to your design.