Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Behavior Designer - Behavior Trees for Everyone

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

  1. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    1. The Movement Pack currently only supports Unity's NavMesh. I do in the future plan on updating it to use the A* Pathfinding Project as well but I don't have a timeframe on that. I haven't taken a look at that API yet but I don't think it would be too hard to adopt the current code based on Unity's NavMesh to the A* Pathfinding Project. Once you get one task done I bet all of the other tasks will have very similar changes.

    2. Behavior Designer does include some basic Animator tasks. Those should give you a good start in making more advanced tasks.
     
  2. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Hi opsive,

    I didn't see all the documentation yet, but have you some basic examples of a task( i mean really basic) or an action in Unity script. Since i don't use c# and in this terms i will have some dificulties with the syntax. I'm not a pro scripter! It will help a lot to have a starting point. In my case, a simple task returning true or false will be enought. (Sorry if this is already covered anywere in the documentation!)

    Thanks!
     
  3. aljovidu

    aljovidu

    Joined:
    Aug 7, 2013
    Posts:
    7
    I'm sure this has been addressed, but I can't seem to find it anywhere.

    It doesn't seem like any of the classes derive from MonoBehaviour. Is there a (simple) way to integrate Unity's event hook methods into Behavior Designer? Eg:

    Code (csharp):
    1. public TaskStatus OnTriggerEnter(Collider trig){
    2.     if(trig.tag == "Bullet") return TaskStatus.Success;
    3.     return TaskStatus.Failure;
    4. }
    or:

    Code (csharp):
    1. private bool _success;
    2. public override TaskStatus OnUpdate(){
    3.     if(_success) return TaskStatus.Success;
    4.     return TaskStatus.Failure;
    5. }
    6.  
    7. public void OnTriggerEnter(Collider trig){
    8.     if(trig.tag == "Bullet") _success = true;
    9. }
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    @Danirey -

    Sure, here's a very basic action that will immediately return success:

    Code (csharp):
    1.  
    2. #pragma strict
    3.  
    4. class UnityScriptAction extends BehaviorDesigner.Runtime.Tasks.Action
    5. {
    6.     function OnUpdate()
    7.     {
    8.         return BehaviorDesigner.Runtime.Tasks.TaskStatus.Success;
    9.     }
    10. }
    11.  
    From what I've found it doesn't look like UnityScript supports the "using" statement so you always have to write out the full namespace.. somebody please correct me if I'm wrong, I don't claim to be a UnityScript expert :)

    @aljovidu -

    If the task is running it will receive the OnTrigger/Collision callbacks, with the same syntax as what Unity uses (similar to your second example). Just make sure you override the method. The MiniGauntlet sample project has an example of this. Note that I forgot to add the 2D callbacks in the current version so those will not be called. It has already been added and will be fixed in the next version.
     
  5. aljovidu

    aljovidu

    Joined:
    Aug 7, 2013
    Posts:
    7
    I'll check it out. Thanks a ton, this will be a huge timesaver. :)
     
  6. Danirey

    Danirey

    Joined:
    Apr 3, 2013
    Posts:
    548
    Thank you so much!!!!

    I agree with @aljovidu. This will help a lot! ;)

    Cheers!
     
  7. red2blue

    red2blue

    Joined:
    Feb 26, 2013
    Posts:
    200
    Hi opsive,

    i have a question regarding calling a specific method from a script out of a behavior.

    Just to give you a quick overview: I wrote an AI that is following waypoints as long as it sees an enemy. If it sees the enemy, it turns to the enemy and shout fire a shot. Now I have the following problem. I want to get the script (which handels shooting) via "GetComponent" and call the method. Since I would like to write a behavior that I can use all over again doesn't matter what the (shoot)- method is called,I wanted to use a string input for the method name. Do you have an idea how I would build up this?

    Or what is your way to interact with a specific script and its methods?

    Thanks a lot!
     
  8. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    You can interact with another component/GameObject pretty much the same way you would with a standard MonoBehaviour object. For example, if you have a behavior tree on the AI that is following the waypoints, to get the script that handles shooting you would do:

    Code (csharp):
    1.  
    2. public override TaskStatus OnUpdate()
    3. {
    4. ....
    5.    var weaponHandler = gameObject.GetComponent<WeaponHandler>();
    6. ...
    7. }
    8.  
    If you want to use a string to determine which component to get you can just use that version of GetComponent:

    Code (csharp):
    1.  
    2. public override TaskStatus OnUpdate()
    3. {
    4. ....
    5.    Component myComponent = gameObject.GetComponent("MyComponentType");
    6. ...
    7. }
    8.  
    Similar to a MonoBehaviour object, you could also make a public variable that you assign within the inspector to the component that you are interested in. One more way would be to use SendMessage if you wanted to. Basically, there isn't a trick to it and you can just do what you already know.
     
    Last edited: May 7, 2014
  9. red2blue

    red2blue

    Joined:
    Feb 26, 2013
    Posts:
    200

    Thanks a lot. That was quite easy. But is there a way to call a method / function wit using a string?
    Sorry for bothering you with this kind of questions. Do you write your own behavior every time you want to call a specific function of a specific script? I allways try to code for a lot of cases so I make the work once :)

    Cheers!
     
  10. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    No problem. To call a method with a string you can either use SendMessage or Invoke. In terms of if I write a single task to call a specific function of a specific script, that completely depends on the design of your behavior tree. There really is no right or wrong way. If you take a look at the RTS sample project you'll see that I have written a task that seeks towards a position and another task that plays an animation. I could just have easily combined those two together. Sorry for not really answering the question but I hope that it answers the question :)
     
  11. red2blue

    red2blue

    Joined:
    Feb 26, 2013
    Posts:
    200
    Thanks a lot for your time and help. I right now ended up writing tasks for the specific case. It is ok, but I am still running into little troubles. I will try to fix them by myself now. Behavior Designer is really cool, but I have to get used to it (Didn't know all the tasks right now and missing kind of loops and stuff like that). Right now I am thinking, that with normal coding I could be faster, but I think (hope) that Behavior Designer will save me time after lerning it.....(Maybe I shoud have a sleep about it...its 00:38 AM... :) )
     
  12. electroflame

    electroflame

    Joined:
    May 7, 2014
    Posts:
    177
    Thanks for responding! The Unity NavMesh is going to be a killer for me, so I'll definitely have to use something else. I'm glad you have future plans for the A* Pathfinding Project, though.

    I'll do a little more research tonight about the A* Pathfinding Project's API and go through some more of your documentation, but I think that Behavior Designer + A* is going to be the perfect combo for what I need. Unless I run into some major issues in the docs, I'll more-than-likely pick up Behavior Designer + the Movement pack tomorrow.

    Thanks!
     
  13. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Great to hear! Yeah I definitely plan on updating the movement pack to support the A* Project, it will probably be shortly after Behavior Designer 1.3 comes out (currently working on fixes for 1.2.5, then will start on 1.3)
     
  14. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,649
    Good move. Really... Thanks :D
     
  15. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Hey opsive,

    I've been playing around with Behavior Designer and I love it so far. It really speeds up my workflow.

    I'm having some issues assigning shared variables from outside of the tree. I currently have a tree that I call often in multiple situations. It has two shared variables: target and distance, which I set from outside of the tree right before I run it. The code I use to do so is as follows:

    Code (csharp):
    1.  
    2. public class CallMoveTree : Action {
    3.     public BehaviorTree moveTree;
    4.  
    5.     public SharedTransform target;
    6.     public SharedFloat distance;
    7.  
    8.     public override void OnStart() {
    9.         moveTree.SetVariable("target", target);
    10.         moveTree.SetVariable("distance", distance);
    11.         moveTree.EnableBehavior();
    12.     }
    13. }
    14.  
    When I run the code, it throws "ArgumentException: An element with the same key already exists in the dictionary." and the variables within the called tree become:
    $SS1.PNG

    When I unpause, the same exception is thrown and the variables within the tree become:
    $SS2.PNG

    Note that 'Left" is the correct transform (though there should only be one "target" variable), and 1 is the correct value for the direction. Each time I unpause after that, it throws another of the same exception and creates a no-named SharedFloat with a value of 1.

    Am I misunderstanding how SetVariable works? Also, is there a way to call this tree from a single saved tree, rather than having to add it to every GameObject that calls it from other trees?

    Thank you for the help, and for the great asset!
     
    Last edited: May 9, 2014
  16. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Hi RobRas,

    Happy to hear that you're enjoying it. In the current version there is a bug with SetVariable that you may be hitting. If you extract the source code version you can fix it by adding the following in line indicated by the arrow to line 93 of BehaviorSource:SetVariable:

    Code (csharp):
    1.  
    2. ...
    3.             item.name = name; // <-------
    4.             if (mSharedVariableIndex != null  mSharedVariableIndex.ContainsKey(name)) {
    5. ..
    6.  
    Edit: I thought that you were reassigning a variable back to the tree that it came from. After looking at your code some more it looks like I thought wrong and you are actually assigning the variables to a new tree.

    In terms of calling the tree from a single saved tree, yes, there is. Save the tree out as an external behavior tree and then you can reference that tree either through the behavior tree reference task or through code with the external tree variable.
     
    Last edited: May 9, 2014
  17. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Thanks for the fast response!

    I edited the source as suggested, but it didn't seem to fix the issue. I certainly won't complain about bug fixes though. :) "target" and "distance" already exist in the tree, though I also tried dynamically adding them with new names and assigning them to "target" and "distance" from within the called tree, but I ended up having the same problem. Interestingly enough, despite me changing the SetVariable names to "t" and "d" when trying it dynamically, the newly created variables were still of the name "target". "distance" was not changed at all when I attempted dynamic assignment.

    Thanks! I'm still a little confused about how to go about calling the tree. Am I understanding this correctly? First you create a BehaviorTreeReference task within the calling tree. Then set its ExternalBehaviors[0] to the saved External Tree. From here, how would I go about manipulating the tree itself with code? Am I totally off the mark with this code?
    Code (csharp):
    1.  
    2. public class CallMoveTree : Action {
    3.     public BehaviorTreeReference moveTreeReference;
    4.  
    5.     public SharedTransform target;
    6.     public SharedFloat distance;
    7.  
    8.     public override void OnStart() {
    9.         moveTreeReference.externalBehaviors[0].SetVariable("target", target);
    10.         moveTreeReference.externalBehaviors[0].SetVariable("distance", distance);
    11.         //run tree?
    12.     }
    13. }
    14.  
     
  18. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    I'll replicate your shared variable scenario and see if I can find out what is happening.

    Edit: There was a bug with this scenario. It will be fixed in version 1.2.5.

    In the meantime, lets take a step back. What are you trying to accomplish? From that I should be able to suggest the best way to implement it.
     
    Last edited: May 10, 2014
  19. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Sounds good, thanks!

    I'm just trying to make my trees a bit more modular. The tree I'm trying to call moves the GameObject it's attached to towards "target" while the GameObject is "distance" away from it. It also plays the GameObject's movement animation if there's one available. I could always code it as a single, larger task instead of a tree of smaller tasks, or copy and paste the tree's tasks inside the calling tree, but I would prefer to keep it as a single tree that I can reference if that's possible.

    I currently only have one GameObject calling the tree, though I would have just about any object that moves calling it once I get it worked out. Right now I have a larger tree that determines the GameObject's movement behaviors. When the larger tree decides the GameObject should move, it should call the movement tree. Here's a picture of the larger tree to give you a bit more of an idea of what I'm going for.
    $SS3.PNG

    The movement tree is a much simpler tree that would otherwise get repeated several times within the above tree.
    $SS4.PNG

    Thanks once again!
     
  20. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Thanks, that helped.

    Here's how I would approach it:

    1. Save that movement tree out to an external behavior tree.
    2. Use the behavior tree reference task within the larger tree in the places that you would otherwise repeat those movement tasks.

    Now you should have all of the tasks setup properly, and just need to worry about the shared variables.

    3. Use the InheritedField attribute on your target and distance shared variables (look towards the bottom of the page for inherited field). This will transfer the variables from your main tree to the external tree.

    The RTS sample project has an example of almost this exact scenario. Take a look at the behavior tree attached to the unit. Within that tree it has two behavior tree reference tasks that do the actual attacking on the target. It uses the inherited field so it knows what target to attack. You will need to subclass the external behavior tree task so you can add the inherited fields but you shouldn't manually have to set the variables
     
  21. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Ah, looking over it that seems exactly what I need to do. Thank you so much!

    I'm having a new issue now, however, mostly caused by my own stupidity. I meant to remove one of my assets, but accidentally deleted Behavior Manager instead while the Behavior Manager UI was open. This caused an blank frame to appear which could not be closed. Upon importing Behavior Manager again, Unity crashed, and now the project I was working on crashes on startup.

    I copied the scripts that I wrote from my project over to a new project and imported Behavior Designer, to be met with the following issue:

    When saving a new external tree, it throws an "InvalidCastException: Cannot cast from source type to destination type." exception. When I try to open the newly saved tree, I'm getting spammed with two more exceptions: "rc.right != m_GfxWindow->GetWidth() || rc.bottom != m_GfxWindow->GetHeight()" and "InvalidCastException: Cannot cast from source type to destination type." The latter being fired off twice for for each of the former. The Behavior Designer UI won't open, and when I try a second time to open it Unity crashes.

    Totally fresh projects with Behavior Designer work just fine, so I'm guessing there's something in one of my scripts that's causing the issue. However, the exceptions are not specific enough to determine the cause. Here's the rest of the InvalidCastException that is thrown on repeat:

    edit: the project that crashes was one that I made to test out Behavior Designer, so I'm didn't lose anything important in it.
     
    Last edited: May 9, 2014
  22. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Yeah the Behavior Designer editor isn't going to like it if you delete the Behavior Manager script while it is running.

    The first thing that I would try is to change the window layout (the drop down box on the top right of the Unity editor). That will clear the cache for the editor windows and that should prevent those "rc.right" exceptions. The exception that you makes me think that the serialization data for your tree got corrupted. Is this tree on a prefab? If you want to send me that prefab I can take a look at the serialization to see if I can correct it. Or if you have a backup it may be quicker to just revert to that.
     
  23. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Yeah, I need to learn to look before I delete. :p

    I'll play around with it and see if I can get it working. Worst case scenario I'll just make a new project. I created the project to toy around with Behavior Designer, so I didn't use any source control, but I also didn't lose anything of value.

    Thanks again for all the help, and for the incredibly fast responses. Behavior Designer will definitely be making my projects easier to manage!
     
  24. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Sounds great. Obviously data corruption is a big deal so if you happen to hit that same error again let me know.. I really don't think you will though based on the steps that it took to get into that situation.
     
  25. RobRas

    RobRas

    Joined:
    May 9, 2014
    Posts:
    9
    Hey opsive, I've been toying around with Behavior Tree Reference tasks and am running in to a bit of a problem with multiple of the same references in one tree. Hopefully you can shed some light on the issue. The tree giving me problems is this one:
    $TreeHelp1.PNG

    Move To Distance Tree Reference has the following variables:
    $TreeHelp2.PNG
    The only difference between the two references is the "distance" value. All three variables are passed as InheritedFields.

    When I have only a single reference task, the tree works flawlessly. However, upon adding the second (or more), the following happens:
    Regardless of which reference task is called, the value of "distance" being inherited by the external tree is the "distance" value given to the first reference task of it's type in a depth-first search. This occurs whether the task is reachable or not, and still occurs even if the task is disabled.
    When PlayerIsMoving returns failure, the tree works correctly (other than the problem above). However, when PlayerIsMoving returns success, both Call1 and Call2 are called in the same frame, again both having Call1's "distance" value.
    When I changed "distance" to a Tree-wide variable that I modified to the appropriate value in a task right before calling each reference task, the correct values were passed, but the above problem of both Call1 and Call2 being called on PlayerIsMoving's success still occurred.

    It may also be relevant to mention that upon adding a one or more of the reference tasks to the tree, it no longer lights up.

    Thanks once again for the excellent customer support, and the incredibly helpful asset!
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Everything looks like it is setup correctly.. Is this tree one that you can send to me so I can take a closer look? My email is support@opsive.com.
     
  27. nixter

    nixter

    Joined:
    Mar 17, 2012
    Posts:
    320
    EDIT: Nevermind. I got a new BT working from scratch. I'll see if I can track down what went wrong.
     
    Last edited: May 10, 2014
  28. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    If you instantiate a prefab with a behavior tree on it and start with enabled is true then it should start as soon as that prefab is instantiated. Yeah if you are able to reproduce the problem I would love to take a look.
     
  29. Rod-Galvao

    Rod-Galvao

    Joined:
    Dec 12, 2008
    Posts:
    210
    +1 for Aaron's A* integration
     
  30. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    Hi, I run the playmaker sample with playmaker 1.7.7.1 there are 31 errors. I can't import globals in the resource folder it says "no globals to import". Did I miss anything?
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    What are those errors?
     
  32. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    I can't list it all here but a screenshot may help you to understand the problem.
    $Screen Shot 2014-05-10 at 9.04.05 PM.png
     
  33. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
  34. tr1stan

    tr1stan

    Joined:
    Jan 23, 2009
    Posts:
    150
    @opsive, problem solved. Thanks for your supper fast support!
     
  35. Raveler

    Raveler

    Joined:
    Sep 24, 2012
    Posts:
    40
    Hey... I'm having serious troubles with Behavior Designer. I now get these errors spammed to the console continually:

    ArgumentException: item
    System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Interrupt].System.Collections.IList.Add (System.Object item) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:668)
    BehaviorDesigner.Runtime.DeserializeJSON.Deserialize (BehaviorDesigner.Runtime.BehaviorSource behaviorSource)
    BehaviorDesigner.Runtime.BehaviorSource.CheckForJSONSerialization (Boolean force)
    BehaviorDesigner.Editor.TaskCopier.CheckTasks (IBehavior behavior)
    BehaviorDesigner.Editor.BehaviorInspector.Reset ()

    ArgumentException: item
    System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Interrupt].System.Collections.IList.Add (System.Object item) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:668)
    BehaviorDesigner.Runtime.DeserializeJSON.Deserialize (BehaviorDesigner.Runtime.BehaviorSource behaviorSource)
    BehaviorDesigner.Runtime.BehaviorSource.CheckForJSONSerialization (Boolean force)
    BehaviorDesigner.Editor.GraphDesigner.Load (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, Boolean loadPrevBehavior, Vector2 nodePosition)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, Boolean loadPrevBehavior, Boolean firstLoad, Boolean reposition, Boolean inspectorLoad)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateTree (Boolean firstLoad)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.OnGUI ()
    System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)

    This error now keeps spamming my console, even if I don't have the Behavior Editor open. I basically can't do anything in my project anymore, it completely clogs up my console and I can't find a way to make it leave. I had this error before, and the only way I got it to leave was by deleting the BehaviorTree script from the prefab... which also deleted the associated behavior tree.

    I really don't want to do this now because my tree is very huge and I can't reproduce it by heart anymore. What should I do? I was just messing around with the shape of the tree when this happened... I wasn't doing anything weird. The editor stopped responding (I was dragging lines between nodes, and they started generating errors in the console), so I rebooted Unity and now it's broken entirely.

    I would appreciate the help! I'm really scared of losing my tree.
     
  36. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Can you send me the scene/prefab and the associated scripts so I can take a look (support@opsive.com)? Definitely don't delete the tree - I should be able to recover it and figure out what went wrong. Also, you can probably stop it from spamming the console with errors by changing the window layout in the top right corner of the Unity editor.
     
  37. Raveler

    Raveler

    Joined:
    Sep 24, 2012
    Posts:
    40
    I can't really isolate them, I'd have to send hundreds of files... It's part of a pretty large project. Where is the tree stored? Is it stored within the prefab? I might be able to make a light-version of the prefab by copying it and deleting all the monobehaviors.
     
  38. Raveler

    Raveler

    Joined:
    Sep 24, 2012
    Posts:
    40
    Changing the layout does not stop the errors, I just tried. They always start when I select the prefab, whether the behavior editor is open or not.
     
  39. Raveler

    Raveler

    Joined:
    Sep 24, 2012
    Posts:
    40
    I can't make a copy of the prefab either; it gives the same error when I try. There is really no way to do anything with the prefab without deleting the BehaviorTree MonoBehavior first.
     
  40. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    Can you send me the prefab with the associated tasks? If you can't send me the tasks that's fine - I can just get it to the point that it will load and then you can check to make sure everything is working properly.

    Edit: Raveler sent me his tree and everything was still in tact. I have a fix to prevent this error from happening again and it will go in version 1.2.5. In the meantime, if anybody else experiences this error please get in contact with me.
     
    Last edited: May 10, 2014
  41. BortStudios

    BortStudios

    Joined:
    May 1, 2012
    Posts:
    48
    opsive, I was wondering if there is functionality in this tool to more quickly create assets to be used? I find it slightly tedious to create a new script, change its parent, remove its standard update functions and replace them with the tool's, etc. It would be incredibly useful and timesaving if there were a button somewhere where we could click to create a new, say, Action, and it loads up a base script you've made, all ready for us to put in our code. Perhaps if you right click on an empty space on the blackboard you can open up a menu to create new -> Action, and it makes it and opens up the script?

    This is a really great tool, and that would be a huge quality of life improvement, for me, at least. Unless I am missing something - this functionality may already be in it, and I could just be not seeing it.

    Great work on it, though, I really love it
     
  42. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    That's a great idea! I'll add it in version 1.3 (will be submitting 1.2.5 within the next few days and then will be started on version 1.3)
     
  43. kotor

    kotor

    Joined:
    Dec 3, 2013
    Posts:
    140
    opsive,

    I recently bought both the Behavior Designer and Movement package. When I am using the Patrol task I don't seem to figure it out how to control the speed of a agent. Event if I put different values in speed parameter the agent seems to move with the same speed. I want the agent to walk when patrolling and run when find the player within sight. Please advice where I am doing wrong ? Thanks
     
  44. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    In build, the following code logs null where indicated. The code runs without error in play mode.

    Code (csharp):
    1.  
    2.             var newGameObject =
    3.                 (GameObject)Instantiate(
    4.                     original: _workerPrefab,
    5.                     position: _generatePoint.position,
    6.                     rotation: _generatePoint.rotation);
    7.  
    8.             Debug.Log(this.gameObject);
    9.             Debug.Log(this.gameObject.name);
    10.             Debug.Log(this.gameObject.transform);
    11.             Debug.Log(newGameObject.GetComponent<Behavior>().GetVariable("Base")); // Indicated
    12.  
    I have seen a link for a distribution version; however, it sounds like it's for Asset Store sales, not general build versions.
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    @kotor -

    The speed is set within the OnAwake method of the task so if you adjust it while the game is playing then the changes will not take effect. From your description it looks like you want the speed to be set during OnStart versus OnAwake. In that case move
    Code (csharp):
    1.  
    2.             navMeshAgent.speed = speed.Value;
    3.             navMeshAgent.angularSpeed = angularSpeed.Value;
    4.  
    to OnStart. If you want the speed to be able to changed while the task is running then move these two lines to OnUpdate.

    @SeriousBusinessFace -

    The distribution version shouldn't have anything to do with this error. Have you defined the variable "Base"? If that hasn't been defined then it will return null.
     
  46. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    It's been declared, but has been left as "none", so no.

    To sum up, I used something like ".GetVariable("Name").SetValue(value);", as the SetVariable() method requires a SharedVariable to change the value of the variable (unless I missed something).

    I was probably thinking that a SharedVariable initialized to "none" would simply have a ".value" of null.
     
  47. S0ULART

    S0ULART

    Joined:
    Jun 14, 2011
    Posts:
    131
    Hi opsive,
    I get the following error after starting a new project > importing playmaker > behaviour designer > playmaker assets > playmaker samples

    "Assets/Behavior Designer Samples/PlayMaker/Scripts/CharacterMotor.js(24,13): BCE0055: Internal compiler error: Missing or incorrect header for method EnterBinaryExpression."

    any suggestions?
     
  48. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,455
    @Opsive, nice package.

    I noticed that there is a comparison matrix between BD and Node Canvas, does BD also support FSM ? If not, could this be added in a future update. Reason is that although BT are really good but there are situations where FSM are better suited. Combining BD and FSM together in one package like Node Canvas offers greater flexibility and power.

    edit: Does BD support Mecanim and how does BD compare with Rain http://rivaltheory.com/rain/features/?
     
    Last edited: May 11, 2014
  49. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,777
    @opsive - agree nice package... but got issues with windows 8 mobile - it wont compile:

    Internal compiler error. See the console log for more information. output was:
    Unhandled Exception: System.TypeLoadException: Could not load type 'BehaviorDesigner.Runtime.Tasks.Task' from assembly 'BehaviorDesignerRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    at (wrapper managed-to-native) System.Reflection.Assembly:InternalGetType (System.Reflection.Module,string,bool,bool)
    at System.Reflection.Assembly.GetType (System.String name, Boolean throwOnError, Boolean ignoreCase) [0x00000] in <filename unknown>:0
    at System.Reflection.Assembly.GetType (System.String name) [0x00000] in <filename unknown>:0
     
  50. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,093
    @SeriousBusinessFace -

    You should be able to set the value directly with:

    Code (csharp):
    1.  
    2. var myVariable = behaviorTree.GetVariable("Name");
    3. if (myVariable != null)
    4.    myVariable.Value = myValue;
    5.  
    Where "myValue" is the value that you want to set it to. You shouldn't need to use SetValue. SetVariable is used if you want to create a completely new variable within code.

    @S0ULART -

    CharacterMotor.js is a script from the standard unity assets package. There is probably a conflict somewhere - do you already have a CharacterMotor.js imported?

    @rocki -

    My goal for Behavior Designer is to be a great behavior tree implementation - nothing more, nothing less. I do not plan on integrating a FSM because if you want a FSM you can use PlayMaker. I feel that if I spent time adding a FSM then that would lost time for making the behavior tree implementation better. In terms of if it supports mecanim, Behavior Designer doesn't really care what technology is used within your tasks. If it works inside MonoBehavior then it will work inside a Behavior Designer task. With that said, I have included some basic mecanim tasks and you can see the list at http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=72. I have only briefly used RAIN so I can't say for certain but I think that in the comparison matrix it would look similar as React. It does have more documentation written for it though.

    @AdamGoodrich -

    For some reason Windows Mobile doesn't like the runtime DLL. If you extract the source code then it will work. I will play around with it to see why it doesn't like it but at least for now there is a workaround.