Search Unity

Behavior Designer - Behavior Trees for Everyone

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

  1. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    Thanks Justin, I understand what's happening much better now. And I really, really hope you can manage to drastically reduce the number of calls and/or computation time involved, as all my AIs use a fairly simple tree of 5 or 6 tasks (and only one running at any time).

    So keeping my fingers crossed...!! :)
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    Just wanted to put a word in for Behavior Designer. Opsive puts a lot of effort into making it easy to integrate with other products (such as the Dialogue System). It's not only a huge timesaver, but you know ahead of time that the products work together. It's awful to invest a lot of time in two products only to find that they're not compatible.
     
  3. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    I concur. Not only that but any quick look at this thread will show that @opsive is doing an excellent job at supporting this asset.
     
    TonyLi likes this.
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I really appreciate it @ToniLi and @Seith. I always find that it means much more to hear from customers regarding a specific asset rather then the publisher of the asset. Of course the publisher is going to be in favor of their asset and think that it is better than the rest, but when you have actual customers respond that means so much more. Speaking of Dialogue System specifically, that was one of the first assets that Behavior Designer was integrated with and the two systems work really well together. Tony put together a really comprehensive system.

    To @Seith specifically - I sent you a PM with a link to a new version. OnTriggerStay should no longer be called if a task doesn't implement that method.
     
  5. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @opsive I just tried the new version you PMd me and it works great! Now BehaviorDesigner is nowhere near the top of the profiler anymore! Thank you so much Justin! Now that's what I call optimization... :)
     
  6. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    That's awesome! This version also contained another optimization to reduce the calls to a relatively expensive function so you should see some non-physics related optimizations as well. I should be able to release this version tomorrow, just working on one more integration. As a heads up, the integrations that are already complete include:

    Anti-Cheat Toolkit
    Cinema Suite
    Pool Boss
    Uni2D

    And I'm working on Realisitc FPS prefab now.
     
    OnePxl and hopeful like this.
  7. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Behavior Designer 1.4.5 is out on the Asset Store now and has been sent to opsive.com purchases. The highlights of this update include adding global variables to the Variable Synchronizer and lots of minor bugfixes/optimizations. You can view the full update notes here.

    Edit: I forgot to mention, if you are using PlayMaker integration make sure you download the new tasks from the integration page. The Variable Synchronizer now supports PlayMaker global variables so you'll get a compile error if you don't have the latest.

    The following third party integration tasks have been added:

    Anti-Cheat Toolkit



    Cinema Director


    Pool Boss


    Realistic FPS Prefab


    Uni2D
     
    Last edited: Dec 13, 2014
  8. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    A nice selection of integrations!

    Would it make sense to add some integrations for vehicle behavior, like Edy's and/or Road & Traffic?
     
    eridani likes this.
  9. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I like the idea - currently I don't have any vehicle integrations so I'll add it to the list.
     
    Last edited: Dec 14, 2014
    eridani and hopeful like this.
  10. OnePxl

    OnePxl

    Joined:
    Aug 6, 2012
    Posts:
    307
    I second that request!
     
  11. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    New user, excitedly trying it out.

    Very happy about the videos. Thanks.
     
  12. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    @hopeful & @OnePxl -

    If I were to only add one vehicle integration to the next Behavior Designer version, should it by Edy's? And what type of tasks do you want to see for it?

    @twobob -

    Welcome! Don't hesitate to ask if you have any questions. In addition, the opsive forums is a great resource.
     
    twobob likes this.
  13. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    I'm not sure. Edy's is one of those assets a lot of people have - and I have it too - but I've not done much with cars yet, as I've been waiting for about a year or so on EasyRoads3D v3 (with intersections), which is hopefully going to make it out of beta someday in January or something. (Fingers crossed!)

    Road & Traffic is newer than Edy's and probably owned by a lot fewer people, but it is a very reasonably priced traffic plugin. It already manages basic traffic AI behavior, like stopping at red lights, changing lanes, and avoiding collision.

    I will probably be trying to use all 3 plugins (Edy's, R&T, and ER3Dv3), if that's possible, plus BD.

    So what I think people would want to use Behavior Designer for in relation to cars is to manage car entry/exit (hijack or otherwise), player and NPC driving in relation to each other and to destinations, pedestrians (avoidance?), and the like. For example, if you wanted to have a player drive, and for the police to be alerted if the player is driving crazy, and for the police to follow and attempt to engage ... or maybe the player is in the role of police, and they need to chase down car thieves or head to a bank robbery that's been called in ... that seems like something you'd want to have Behavior Designer help with.

    My take on it is that a person would want to have a hookup to something like Edy's to get control of a vehicle's speed and steering independent from roads (so you can drive on sidewalks, across the plaza, and through fields), but you'd need something like Road & Traffic to know where the road is, to know when you're at an intersection, and to manage simple vehicle avoidance. Being able to turn on car lights (linked to time of day), brake (with brake light flash), signal turns, turn on/off siren, open and close door, maybe leave skid marks, and so on would be some standard behaviors to control, whichever way you go.

    It's the kind of thing where probably just a couple of parameters would get hooked up at first, and then hopefully more later if people are interested in using BD this way.
     
    eridani likes this.
  14. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    I just bought Behavior Designer primarily because TonyLi endorses it. I'm pretty much in awe of TonyLi's fast coding skills and unbelievable customer service when it comes to his own Dialogue System asset so if he says it's good, it must be good :)
     
  15. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Please create a vehicle combat AI! There's lots of vehicle racing AI out there but I have never yet seen a vehicle combat AI in the marketplace. It's a glaring hole.

     
  16. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Wow @hopeful I was not expecting that detailed of a response, thank you. With yours and @eridani responses you gave me a lot to think about. What will probably happen is that I will do a relatively basic integration with Road & Traffic or Edy's (or both?) and see what type of response I get from that. If a lot of people are using it then I can work on something a little bit more involved. Having something like that Indestructible video would be really cool.

    And thanks @eridani. Tony really does a great job, and hopefully Behavior Designer will meet the good qualifications :)
     
    eridani likes this.
  17. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    I tried out ed's, and a bunch of other solutions for vehicular movement.

    My take is that Edy's is okay (amazing physics) but really lacks the extensibility at the moment to be practicable in many titles (lack of vehicles, AI is very shaky on the demo, in steps you) BUT - what with the 5.0 release being right around the corner - and Eddie saying that he is going to be revamping the physics extensively [http://blogs.unity3d.com/2014/07/08/high-performance-physics-in-unity-5/] "Edy is currently working on the new version of his package which will bring more amazing stuff. Contact him directly for more details." - since he dislikes the new 3.3 vehicular rig [Insert other link here if I find it] - I fear that you may end up doing the work twice.

    Either way, it is a nice setup, one thought would be to get one of the better free rigs and hook into that, providing access to vehicular movement for all - then - when Edy decides that the time is right to release to release "Edy's Mark II" (or w/e it is going to called) get in on that then.

    Meh, those are my thoughts fwiw. Not sure which would be the best "Get people on board to your package" direction to take, but integrating to free packages will certainly "apparently lower the bar to entry".

    The post by hopeful above addresses my other thoughts on multipackage integration neatly.
    props for that hopeful
     
    Last edited: Dec 15, 2014
  18. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    My thought on the integration with Edy's is to be very basic, something like "set velocity," "turn degrees right," "turn degrees left," "is car flipped" and "unflip car." This sort of thing should translate fairly easily from one version of Edy's to the next. I'm not sure where BD's scripting would go after that, but it would likely come after 5.0 and the Edy's upgrade.

    My impression is that Edy's is the most widely owned vehicle physics plugin out there, though possibly BD could also do something with the car package in Standard Assets.

    EDIT: Yeah, I mean Sample Assets Beta. :)
     
    Last edited: Dec 15, 2014
    twobob likes this.
  19. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    ^ this. Sample Assets Beta though. Not standard assets


    EDIT: Thinking about it.... Why not just do a "WORKED" video of hooking up to sample assets beta. That would
    a) achieve the extra extension hookup to the new upcoming Samples Assets package
    b) teach people to write their own hookups by actually watching and learning.
    c) give you an opportunity to expand that "http://www.opsive.com/assets/BehaviorDesigner/images/WritingNewTaskVideo.png" video to be hopefully practically applied in a real world situation.

    This sounds like a genuine decent business decision to me.
     
    Last edited: Dec 15, 2014
  20. chelnok

    chelnok

    Joined:
    Jul 2, 2012
    Posts:
    680
    Can global variables be used to refer to transform in scene? I'm having a problem; transform goes to none quite randomly, and i started to think they (globalvars) shouldnt be used like this as they are saved to file (BehaviorDesignerGlobalVariables). What is that file anyway, scriptable object?
     
  21. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Awesome. I never would have thought of adding integration for the Sample Assets Beta. Interesting idea on recording a video while I do it. A lot of these integration tasks are just API calls and the real work is done by the asset being used so I'm not sure how much a video would really help. If you compare the integration tasks to the Movement Pack you'll see that the tasks within the Movement Pack do a lot more than just make an API call or two. I don't mind making it though if you still think that it would help.

    It does sound like I should add support for Edy's in the next version. I'll take a look at Road & Traffic as well to see how easily it is to add support for.

    @chelnok - Global Variables have the same restriction that prefabs do in that they cannot refer to objects within the scene. Take a look at this thread for alternative methods to accomplish a similar thing. Yes, Global Variables are derived from ScriptableObject.
     
  22. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    In a nutshell: Never over-estimate your audience.

    Honestly, a really simple "And this is how you do this really obvious thing", and "This is how you do this slightly less obvious thing" is a great starter piece in any training arsenal.

    Doing it with assets they have access to makes it feel personal and useful.
     
  23. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    This. Thanks for the suggestion. :cool:

    Edit :

    "Awesome. I never would have thought of adding integration for the Sample Assets Beta..."
    Shame on you... :p

    Another usefull and 'popular' asset : Realistic Car Kit
     
    Last edited: Dec 15, 2014
    twobob likes this.
  24. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    While we are throwing in insane ideas...

    Why not do something based on Substance files? http://www.allegorithmic.com/user-stories go for a spot on there. I have zero doubt that an AI (okay, state machine) controlling substance files is clearly a scarily awesome prospect if properly implemented.

    Make Substances visibly go back in time (someone manually did that recently), Make substances morph their normals (or something) based on external stimuli, Perhaps automatic camouflage for soldiers based on their surroundings. Make substances for genetically-engineered fish that automatically shift their iridescent hue based on BOIDS aversion principles.
    There must be a myriad of things you can do with that. It would be the most awesome interactive fish tank of all time.

    I would do stuff like that, whilst it is important to respect and integrate your works with the other authors on here it is important not to miss the big picture. Substance: Allegorithmic. Landscape: Speed Tree. Modelling: Mixamo.

    Hookup with the big players too. It will be worth it in the future of 5.0 I would wager.

    Cheers.
     
    Last edited: Dec 15, 2014
  25. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I guess I opened the flood gates asking for integrations :)

    You guys gave me a lot to think about. I have some ideas on where to begin and where I would like to end up. 2015 should be a fun year. I'll keep everybody updated as I make progress.
     
    twobob likes this.
  26. RaiuLyn

    RaiuLyn

    Joined:
    Sep 14, 2014
    Posts:
    39
    At first, I wasn't really intended to get Behavior Designer ever since a neat guy named Justin who came into a conversion out of nowhere a few months back.

    I was quite resistant even to the sale till I hit a roadblock on making AI in my game. I was always thinking Playmaker is all I need to make AI. Finally I caved in because of TonyLi praising Behavior Designer as I really liked Dialogue System for Unity.

    Back to my game, I've been playing around with Playmaker for a while. it's great for putting actions for the AI but I'm conflicted on its decision making. That's why I figure Behavior Designer might remedy this. With Dialogue System for Unity playing a big part of my game, I need NPCs to react and trigger conversations based on moods and memories the NPC is in and has respectively to let them feel alive.

    Anything I should be wary of beforehand?
     
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I need to send @TonyLi a six pack or something for everybody that he has referred to Behavior Designer. Seriously, if you need dialogue for your game, look no further than Dialogue System for Unity. It is so much more than just a dialogue tree system. It is also integrated with a ton of other assets and as you can see from the comments in this thread, is very well supported.

    In terms of your question @RaiuLyn, if you are unfamiliar with behavior trees then it will take a bit to understand how they work but as soon as you do you should be right at home if you've used PlayMaker. Behavior trees are by no means a hard concept, they just take some getting used to. For an overview of behavior trees and some good resources, take a look at this post on the Opsive forum.
     
  28. giraffe1

    giraffe1

    Joined:
    Nov 1, 2014
    Posts:
    302
    Is it complicated to get a basic humoniod rigged mecanim ai with an idle, walk and run state to move around using the movement pack functions (example: patrol) without code or large complicated behavior trees or additional assets (just behavior designer)?
     
  29. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    As long as you aren't using root motion, you should be able to get everything working with any code. The Movement Pack doesn't deal with animations at all, so you'll need a separate task to control the animation. Pretty much the entire animator API is already available through various tasks though. If you are using root motion though then it will take some modification of the Movement Pack tasks because they do their own movement.
     
  30. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    With this recent update, do we need to redownload the movement pack and is it the same link that you sent in your email for people that got it included with BD at the regular price?

    By the way, messed with another behaviour tree (see how I spelled that?) and it was good and got me started, but Behavior Designer for me as a beginner has such a gigantic list of tasks and integrated with so many other editor extensions that I don't think there is another BT asset that even comes close. And the support here and in your own formums is pretty amazing. It's like the playmaker of behavior trees. I can impress (more like confuse) my friends with these pretty boxes lighting up and doing important things!
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    I really appreciate the comments :) When did I send you the Movement Pack? The Movement Pack hasn't been updated on the Asset Store since October, though I am planning on submitting a bugfix release later this week.
     
  32. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    You emailed a link to your dropbox on 12/01/2014, so wasn't sure if the movement pack had any updates in such a short period of time since I downloaded it.
     
  33. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Yeah, no updates since then. When you update the package description it changes the date of the asset but the actual content hasn't changed.
     
  34. MIK3K

    MIK3K

    Joined:
    Sep 10, 2014
    Posts:
    144
    Sounds good, thanks.

    I really, REALLY want your 3rd person controller. There are 3-4 developers on the asset store that are so good I am compelled to buy everything they sell. I would just send you my wallet but it's getting lighter all the time. :)
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Thanks for the complement - we are really looking forward to getting it out next month. For those who haven't seen it yet, our next asset is a Third Person Controller. It will integrate really well with Behavior Designer.
     
    BackwoodsGaming and TonyLi like this.
  36. SuperNewbee

    SuperNewbee

    Joined:
    Jun 2, 2012
    Posts:
    196
    I purchased behavior designer a few days ago. I thought it would be very hard to learn, but I was totally wrong. This is really nice and the RFPS integration in a super nice bonus. Thank you.

    I think the sample assets integration with video is a great idea. They have flying vehicles in it as well.
     
    hopeful likes this.
  37. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,684
    I was thinking the same thing, but I felt I was already asking for too much. ;)
     
  38. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Great to hear @SuperNewbee! And yeah, when I make the Standard Assets integration I'll make sure to record it. I probably won't record the video for all of the tasks since that would be repetitive and boring but I'll make sure to do enough so you can get the idea.
     
    twobob and chelnok like this.
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    A new version of the Behavior Designer - Movement Pack has been sent to opsive.com purchases and will be on the Asset Store shortly. You can see the full release notes here. This release is mostly a bugfix release but does contain some patrol enhancements such as adding gizmos and the ability to patrol the waypoints randomly.

    One thing to note is that the patrol waypoints are now a SharedTransformList instead of Transform[]. Your patrol waypoints will need to be reassigned – sorry about this!

    MovementPackBig.png
     
    chelnok and twobob like this.
  40. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    I have spent a long and frustrating day trying to simply disable a set of spawned based on the distance from the player. With the job respawning when complete so as to track player movements.

    I must be stupid but I just kept getting SharedTranformList object is null on the first OnUpdate (the OnStarts all worked)

    Sigh. I would kill for a few more videos.
    I bought the movement pack as you know, is there a community "disable on Distance" based on Tag I can reference. It's so simple a concept I must be doing something wrong.

    Will reconstruct it and post my setup.
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    The Movement Pack contains a Within Distance task but you want a task that it outside of the distance instead of inside so that task won't work. It is a relatively simple task though so I've modified the Within Distance task and posted it on the Opsive forum. From there your branch should look something like:

    branch.PNG

    A lower priority conditional abort is used to reevaluate the Out Of Distance conditional task every frame. As soon as Out Of Distance returns success (meaning an object is outside of the specified range), it will then convert the distant object's transform into a GameObject. That GameObject is then deactivated. Note that Out Of Distance returns as soon as it finds a single task that it out of distance. If you want to have it check for multiple objects that are out of distance you'll either need to modify the task or place this branch in a repeater that repeats forever and ends on a failure.

    In terms of videos, I definitely will be making a new video as I go through the Standard Assets package.
     
    twobob likes this.
  42. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Awesometastic.

    Ill go check that out!

    No, Just track the player. Like a simple activation bubble. Very useful in real terms.

    Thanks,
     
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    Sorry I'm not following - is the Out Of Distance task not what you are looking for?
     
  44. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Hmm... I got it hooked up. It does the opposite of what I was aiming for, I am obviously not being very clear at all. :(
    I wanted remote objects to watch the player and turn themselves off but still keep the behaviour tree running.
    However this is cool and will certainly come in handy.

    I learned a lot just from hooking that up.

    Hey ho. I saw the problem with my original plan in the beginning, the GameObject would turn itself off, thus the tree.

    I originally tried to identify components of the same gameobject to turn off but when I spawned an object procedurally, I couldn't figure out how to get the reference to "itself" for the next operation.

    Given that (reference) in a global variable I see I could then send a few "Offs" to the components instead. As a programmer I must admit I find using such interfaces frustrating where the code would be trivial but I really am trying. however that said: I also tried to do this via code and got tripped up by the SharedTransform thing going null on me in the OnUpdate. heh. doh.

    Just need to get my head around the basic structures. Please.

    I have read docs, and watched all the vids you linked but am not quite getting enough to hit the ground running.
     
    Last edited: Dec 20, 2014
  45. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Might I also add your solution worked perfectly for the purposes it was meant for, bravo on that.

    EDIT: Someone punch me in the face

    "TOOLTIP: If null the game object is used." sigh. I see. DOooooooooooHHHH!!!!!!

    And Someone punch me in the face again, Yes your solution would be perfect if attached to the player and it could manage all the other objects. Gah. long day. I'l try again tomorrow.
     
    Last edited: Dec 20, 2014
  46. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    hehe, it sounds like you are getting close :)

    Now I see what you are trying to do. You're right in that as soon as the GameObject is disable the behavior tree stops running (you can set it to pause instead but that won't help you in this case). What you could do instead is disable the renderer as soon as the agent is out of the distance. Your Out Of Distance task would be modified to the following:

    Code (csharp):
    1.  
    2.   public class OutOfDistance : Conditional
    3.   {
    4.      public SharedTransform playerTransform;
    5.      public SharedFloat distance;
    6.  
    7.     public override TaskStatus OnUpdate()
    8.     {
    9.       if (Vector3.Distance(transform.position, playerTransform.Value.position) > distance.Value) {
    10.         return TaskStatus.Success;
    11.       }
    12.       return TaskStatus.Failure;
    13.     }
    14.  
    15.     public override void OnReset()
    16.     {
    17.        playerTransform = null;
    18.        distance = 0;
    19.     }
    20.   }
    21.  
    Since you are just comparing against the player you don't need to assign a variable when the Out Of Distance task returns success. From there you can simply disable the renderer of the agent:

    Code (csharp):
    1.  
    2.   public class DisableRenderer : Action
    3.   {
    4.     public SharedBool enable;
    5.  
    6.     public override TaskStatus OnUpdate()
    7.     {
    8.         GetComponent<Renderer>().enabled = enable.Value;
    9.         return TaskStatus.Success;
    10.     }
    11.  
    12.     public override void OnReset()
    13.     {
    14.        enable = false;
    15.     }
    16.   }
    17.  
    Edit: As a programmer I definitely understand if you don't want just one task representing a single API call (as in the case of the DisableRenderer task). As I'm sure you've seen, if you take a look at the CTF and RTS sample projects you'll see that those tasks are more complete in that they provide a higher level of functionality. Once you understand the flow of behavior trees your tasks will be able to contain more functionality in them.
     
    Last edited: Dec 20, 2014
  47. twobob

    twobob

    Joined:
    Jun 28, 2014
    Posts:
    2,058
    Thanks very much for the detailed reply, I will give this another go.

    Possibly just needed a good nights sleep.
     
  48. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    @opsive Hi, I'm trying to enable the BehaviorTree component on a characters using:

    myCharacter.GetComponent<BehaviorTree>().EnableBehavior();

    The character starts the game with the component disabled (the component's checkbox is un-checked in the inspector). And while using the above line works fine I'm surprised to see that although the BehaviorTree is turned on, the component itself still appears disabled in the the inspector (checkbox is un-checked).

    And since I'm testing against the component being disabled by doing a myCharacter.GetComponent<BehaviorTree>().enabled of course the result is wrong. So I was wondering if there is a way to harmonize the state of the component in the inspector and the activation of the actual Behavior Tree. Or at least to query the activation state in a reliable way...

    EDIT:
    I tried using:

    if (behaviorTreeScript.ExecutionStatus != TaskStatus.Running) {...}

    And:

    if (behaviorTreeScript.ExecutionStatus != BehaviorTree.TaskStatus.Running) {...}

    But both error out... :(
     
    Last edited: Dec 22, 2014
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,127
    When the behavior tree is enabled it is ticked through the Behavior Manager so that's why the BehaviorTree component is still disabled - it doesn't actually do anything within an Update loop.

    Checking the ExecutionStatus should work though - what errors are you getting?

    To check that the tree is running, you can also call BehaviorManager.instance.IsBehaviorEnabled(behaviorTreeScript) and that will return true or false depending on if it is enabled. Alternatively, you can register for the callback behaviorTreeScript.OnBehaviorEnd which will fire when the behavior tree is complete.
     
    twobob likes this.
  50. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    755
    So the error I get is: ...error CS0117: `BehaviorDesigner.Runtime.BehaviorTree' does not contain a definition for `TaskStatus' (that's when I try: if (behaviorTreeScript.ExecutionStatus != TaskStatus.Running) {...}

    But everything works if I do (as you suggested): BehaviorManager.instance.IsBehaviorEnabled(behaviorTreeScript)

    Thanks! I would love to be able to use ExecutionStatus but maybe I'm not using it right?