Search Unity

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:
    4,680
    Thanks, I was able to reproduce it.

    That played a large part of it. You have 60 variables and each one is drawn with GUILayout/EditorGUILayout. As soon as I collapse the variables foldout then the speed is improved. The GUILayout class does a lot under the hood and even if I do a static GUILayout.Label("Hi") for the 60 times it causes a framerate drop. I may be able to switch it to Unity's treeview so it only displays a limited number of fields and then that would help.

    There were a couple of unnecessary repaint calls within the editor that I was able to eliminate. This helped improved the editor speed when the variables foldout was collapsed. I'll send you a new version to try out. Keep in mind though that the editor updates whenever a task changes so the more tasks that you have the more it'll have to update to show the latest changes. With an extremely large tree like you have that means a task will constantly be changing so it will have to update often.
     
    Last edited: Mar 12, 2018
  2. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Since you don't have the editor open and there's a framerate drop when you don't have the component selected it sounds like a specific task is causing the bottleneck rather than the editor. If you send me an email with the repro scene I can take a quick look at it but the profiler should show where the bottleneck is in this case so it should be pretty easy to spot.
     
    Last edited: Mar 12, 2018
  3. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    402
    I'm not an expert at all on using the profiler but I selected Deep Profile and Profile Editor and when I select the gameobject with the behavior tree component so it is exposed in the editor, I'm see huge Garbage Collection Allocation (GC Alloc) starting in UpdateSceneIfNeeded.....drilling down to Panel.PaintSubTree() and others.

    Here is a screenshot:
    ProfilerBeahviorDesigner.PNG
     
  4. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    That's with the window opened, correct? I sent you a new version that eliminates one GUI.Repaint call which should help some but the window will still update whenever there is a task change. Since you have such a large tree there are going to be many task changes occurring so that's a lot of updating and I'm not sure of a way around that besides closing the editor window. I could add a preference that indicates the maximum update rate but then you wouldn't see the task changes immediately and that would defeat the purpose of having the window open.

    In that profile window it also doesn't indicate which object called the repaint and when I was testing your scene there were a few other non-BD components that were triggering the repaint.
     
  5. chaneya

    chaneya

    Joined:
    Jan 12, 2010
    Posts:
    402
    Thanks for looking at this. The new version didn't make a difference as far as I can tell. The thing is you can also select a small tree character and see the same problem. If you open up Karl1606023 Puppet Master and select the PlayerController object so all of it's components are exposed in the editor, you'll see it's a very small behavior tree but the slow down is just as bad as with the BruteController tree.

    Thankfully you have the Lock option, otherwise Behavior Designer simply wouldn't work because I probably couldn't debug trees while having that component selected.

    I do have a lot of components on the controller objects on my characters. So it's possible there is something else causing all of the GC allocations. Let me see if I can narrow things down.

    Thanks
    Allan
     
  6. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    I just profiled it with Karl's PlayerController GameObject selected and here's the graph:

    Capture.PNG
    During this time the BD editor window was closed and the Behavior Tree component was visible (along with a few other components). I collapsed and expanded the variables/behavior tree component foldout during this time and you can't tell where I did that within this graph so it doesn't look like the BD editor inspector is causing this specific issue.
     
  7. PerunCreative

    PerunCreative

    Joined:
    Nov 2, 2015
    Posts:
    83
    Solved. The issues were caused by setting gameObject.layer every tick. The method looked like this:

    Code (CSharp):
    1. if(!model.Value.IsVisible())
    2. {
    3.     ((BehaviorServer)Owner).Interactable = false;
    4.     gameObject.layer = 12;
    5. }
    6. else
    7. {
    8.     ((BehaviorServer)Owner).Interactable = true;
    9.     gameObject.layer = 10;
    10. }
    After removing those two gameObject.layer lines everything was ok. But I still don't know why this was affecting only the scene view performance.
     
    opsive likes this.
  8. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    310
    Does not support Unity 2017.4

    HelpURL' is ambiguous between `HelpURL' and `HelpURLAttribute'. Use either `@HelpURL' or `HelpURLAttribute'

    How long till the update ? I notice the last one was back in Oct 17... ( Node C was 21st Mar. 18)
    Droped back to Unity 17.2.0 & I get the same error...

    hhmmm ???
     
    Last edited: Mar 27, 2018
  9. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Do you mean 2018.1? I have the update ready to go, just making sure Unity doesn't make any more changes to the final release before pushing it to the store.
     
  10. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    310
    I'm referring to 2017.2.0f3
    Every time I import B.D and movement pack same error 50 times over.

    HelpURL' is ambiguous between `HelpURL' and `HelpURLAttribute'. Use either `@HelpURL' or `HelpURLAttribute'
     
  11. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    2017.2 is supported with the current version and I just tried a fresh import in 2017.2 and it worked. I've seen reports of people having download issues with the new Asset Store so you'll want to use the old for now.
     
  12. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    310
    I'll try DLing again. 2017.2.0
     
  13. TeagansDad

    TeagansDad

    Joined:
    Nov 17, 2012
    Posts:
    782
    I've been using the current BD version with Unity 2017.3.1f1 and 2017.1.1p3 with no issues at all.
     
    opsive likes this.
  14. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    310
    Downloaded Ver. 2017.2.0

    Same error -

    error CS1614: `HelpURL' is ambiguous between `HelpURL' and `HelpURLAttribute'. Use either `@HelpURL' or `HelpURLAttribute'

    note: when I DL I do not DL all the files . I only tick the Unity editor, documentation, iOs build and web GL build.
     
  15. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Have you tried importing into a fresh project? Another script may be polluting the global namespace. When you import you'll want to import all of the files. You'll also want to clear your download cache:

    https://forum.unity.com/threads/asset-store-download-folder.83620/

    Besides that what is the full stack trace of that error?
     
  16. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    97
    Behavior Designer has integration with Invector Third Person Controller?
     
  17. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    No, it doesn't.
     
  18. Sylmerria

    Sylmerria

    Joined:
    Jul 2, 2012
    Posts:
    250
    Hi @opsive ,

    Just for say, I'm waiting ECS implementation with impatience
    Maybe for the 18.3( end of year). from the Unity CTO, ECS will be stable.

    By the way, any news for formation pack with A* pathfinding ?
     
    blitzvb likes this.
  19. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    I'm really looking forward to it as well. It'll be really neat seeing Behavior Designer working with it :)

    I actually do have the basics working:

    2018-04-01_16-48-53.gif

    I've only tested the column task with four agents but the new IAStarAI interface within the A* Pathfinding Project makes me think that it's going to work this time!
     
    Sylmerria likes this.
  20. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    97
    Do you have plans to create a tutorial to make the integration with Invector Third Person Shooter or create a package for that?
     
  21. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    There are no plans - the Invector controller isn't structured properly to be able to easily add external AI to it. We do have a third person character controller that works great with Behavior Designer though.
     
    Last edited: Apr 2, 2018
  22. Banksy

    Banksy

    Joined:
    Mar 31, 2013
    Posts:
    310
    Regarding BD importing to a new Project... Yes that worked fine.

    Something in my original project is making it throw errors... hhmm, this will be like finding a needle in a hay stack :( ( process of elimination )

    When you say " full stack trace " are you referring to the source of the error. I checked the Editor Log but found nothing regarding BD.

    Here's a screen grab of the error

    error = " Assets/Behavior Designer/Runtime/Actions/BehaviorTreeReference.cs(11,6): error CS1614: `HelpURL' is ambiguous between `HelpURL' and `HelpURLAttribute'. Use either `@HelpURL' or `HelpURLAttribute'

    there are 52 other similar errors - ( just change bold text to - Idle.cs , LineCst, Ray Cast, etc..
     
    Last edited: Apr 2, 2018
  23. claudiorodriguescampos

    claudiorodriguescampos

    Joined:
    Jun 23, 2017
    Posts:
    97
    There is any tutorial (or video tutorial) to integrate Behavior Designer with UFPS or Realistic FPS Prefab?
     
  24. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    Do you have an ETA?
     
  25. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    If it's only a problem in your project then that means that something is polluting the global namespace. In your case it sounds like another script has also created a HelpURL attribute and when C# compiles it doesn't know which one to use. Behavior Designer exists in a namespace to reduce as many conflicts as it can but it won't prevent a global attribute from getting in the way.
     
  26. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
  27. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    I don't - ECS is a major change so I will be waiting for it to be stable before I really dig into it.
     
  28. Orekxl

    Orekxl

    Joined:
    Nov 5, 2014
    Posts:
    5
    Does the movement pack for the project still support integrations with A* Pathfinding? The instructions on the website don't seem applicable in version 4+ of A*... I don't have an AIPathAgent component available.

    UPDATE: It was not immediately clear that I needed to download a second integration package from the website but I think I have it now.
     
    Last edited: Apr 5, 2018
  29. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Thanks for the heads up - I need to update that documentation. The A* integration now uses the IAStarAI interface.
     
  30. xingcid

    xingcid

    Joined:
    Oct 24, 2017
    Posts:
    5
    I would like to make sure two features about Behavior Designer。
    a.Can Behavior Designer run without Unity?(loading from json or other format, running without unity, Unity is just used to edit behavior tree)
    b.Is it thread safe?(for example, two independent behavior trees run in seperate threads)
    Thanks a lot.
     
  31. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Not out of the box, but I have heard of a few people getting the runtime working without it requiring the UnityEngine assembly.

    Because Unity runs in a single thread this has not been tested. When ECS is more stable then I will be taking a closer look at this.
     
  32. xingcid

    xingcid

    Joined:
    Oct 24, 2017
    Posts:
    5
    Thanks for replying so quickly.:)
     
  33. blitzvb

    blitzvb

    Joined:
    Mar 20, 2015
    Posts:
    284
    Considering the benefits of ECS and the fact that it’s going to be the default way to develop, I would suggest (at least I hope) that you begin working on it as soon as 2018.1 is out.
     
  34. musashi917

    musashi917

    Joined:
    Jan 6, 2013
    Posts:
    19
    Hi, I would like to know whether it is possible to create and compose Tree at runtime from script. I would like to give player the ability to "code" in-game the behaviour of their custom made robots.
    Is there some native function to do so, and if not, would it be possible to simply create JSON from script and then load them to replicate the feature?
    The feature "Creating a Behavior Tree from Script" from the doc (http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=55) seems different to what I would like to achieve - as the tree loaded is already existing.
    Thanks!
     
  35. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    I've seen people do this by having a set of external trees that the player then can then arrange based on the functionality that they want, but if you want to create the tasks individually you can do something similar to this post.
     
    Arkade likes this.
  36. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    Strange obscure issue I ran across involving the Selector Evaluator. In the below tree you can can see I have disabled the 2nd sequence from the left. This causes the selector evaluator to not process anything ie it will not run the random selector under it as I would expect, which then should run the BeachComb sequence. If I remove the 2nd seq from the left entirely works just fine. Also if I move the 2nd seq from the left to the right of the random selector ie making it the 3rd in priority then it also works just fine. My guess is its some obscure use case that just fell through the cracks?

    Thanks. Great tool btw.

    upload_2018-4-21_9-41-21.png
     
  37. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Thanks for the heads up. I was able to reproduce it and if it's a fix within the task then I'll just post it here, otherwise we will be releasing an BD update this week so it'll be included in that.

    Glad you're enjoying BD!
     
  38. holdingjason

    holdingjason

    Joined:
    Nov 14, 2012
    Posts:
    89
    You is awesome. BTW I bought years ago before you were on the asset store are updates still being done using the "old" way of getting the zip?
     
  39. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Your invoice should have the URL that points to the package. When there is an update you'll also get an email with this link that you can use to download the latest.
     
  40. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    I have a fix for this and it only requires modification to the SelectorEvaluator task. Add the following to the top of SelectorEvaluator.OnChildExecuted:

    Code (csharp):
    1.  
    2.         public override void OnChildExecuted(int childIndex, TaskStatus childStatus)
    3.         {
    4.             // A disabled task is the equivalent of the task failing for a selector evaluator.
    5.             if (childStatus == TaskStatus.Inactive && children[childIndex].Disabled) {
    6.                 executionStatus = TaskStatus.Failure;
    7.             }
    8.  
     
  41. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Behavior Designer 1.5.12 has been submitted to the Asset Store and is available to opsive.com purchases. You can see the full release notes on this page.
     
  42. Amalfi-Prozen

    Amalfi-Prozen

    Joined:
    Feb 2, 2014
    Posts:
    28
    Hi, I'm using unity 2018.
    I found a fairly annoying bug.


    I decide to change my gameobject, so I change the tree in my prefab.
    If I add a sharedVariable in a parameter of an action of the tree of my prefab, then when I go back to the scene I can no longer use my object because I check this:

    ArgumentNullException: Value can not be null.
    System.RuntimeType.GetField (System.String name, System.Reflection.BindingFlags bindingAttr) (at <e1a80661d61443feb3dbdaac88eeb776>: 0)
    BinaryDeserialization.LoadNodeData (BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.Dictionary`2 [TKey, TValue] fieldIndexMap, BehaviorDesigner.Runtime.Tasks.Task task) (at <42c6db9471014bf4aea7a71e269af019>: 0)
    BinaryDeserialization.LoadTask (BehaviorDesigner.Runtime.TaskSerializationData taskSerializationData, BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.List`1 [BehaviorDesigner.Runtime.Tasks.Task] & taskList, BehaviorDesigner.Runtime.BehaviorSource & behaviorSource) (at <42c6db9471014bf4aea7a71e269af019 >: 0)
    BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <42c6db9471014bf4aea7a71e269af019>: 0)
    BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <42c6db9471014bf4aea7a71e269af019>: 0)
    BehaviorDesigner.Editor.GraphDesigner.Load (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, UnityEngine.Vector2 nodePosition) (at <83dcac56cf0544a0b4d427a15a6e739c>: 0)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.LoadBehavior (BehaviorDesigner.Runtime.BehaviorSource behaviorSource, System.Boolean loadPrevBehavior, System.Boolean inspectorLoad) (at <83dcac56cf0544a0b4d427a15a6e739c>: 0)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.UpdateTree (System.Boolean firstLoad) (at <83dcac56cf0544a0b4d427a15a6e739c>: 0)
    BehaviorDesigner.Editor.BehaviorDesignerWindow.OnSelectionChange () (at <83dcac56cf0544a0b4d427a15a6e739c>: 0)
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) (at <e1a80661d61443feb3dbdaac88eeb776>: 0)
    Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object [] parameters, System.Globalization.CultureInfo culture) (at <e1a80661d61443feb3dbdaac88eeb776>: 0)
    System.Reflection.MethodBase.Invoke (System.Object obj, System.Object [] parameters) (at <e1a80661d61443feb3dbdaac88eeb776>: 0)
    UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C: /buildslave/unity/build/Editor/Mono/HostView.cs: 291)
    UnityEditor.HostView.Invoke (System.String methodName) (at C: /buildslave/unity/build/Editor/Mono/HostView.cs: 284)
    UnityEditor.HostView.OnSelectionChange () (at C: /buildslave/unity/build/Editor/Mono/HostView.cs: 164)


    and

    OutOfMemoryException: Out of memory
    System.Collections.Generic.List`1[T].set_Capacity (System.Int32 value) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
    System.Collections.Generic.List`1[T].EnsureCapacity (System.Int32 min) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
    System.Collections.Generic.List`1[T].Add (T item) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
    System.Collections.Generic.List`1[T].System.Collections.IList.Add (System.Object item) (at <e1a80661d61443feb3dbdaac88eeb776>:0)
    BinaryDeserialization.LoadField (BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.Dictionary`2[TKey,TValue] fieldIndexMap, System.Type fieldType, System.String fieldName, System.Int32 hashPrefix, BehaviorDesigner.Runtime.IVariableSource variableSource, System.Object obj, System.Reflection.FieldInfo fieldInfo) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BinaryDeserialization.LoadNodeData (BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.Dictionary`2[TKey,TValue] fieldIndexMap, BehaviorDesigner.Runtime.Tasks.Task task) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BinaryDeserialization.LoadTask (BehaviorDesigner.Runtime.TaskSerializationData taskSerializationData, BehaviorDesigner.Runtime.FieldSerializationData fieldSerializationData, System.Collections.Generic.List`1[BehaviorDesigner.Runtime.Tasks.Task]& taskList, BehaviorDesigner.Runtime.BehaviorSource& behaviorSource) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BinaryDeserialization.Load (BehaviorDesigner.Runtime.TaskSerializationData taskData, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BehaviorDesigner.Runtime.BehaviorSource.CheckForSerialization (System.Boolean force, BehaviorDesigner.Runtime.BehaviorSource behaviorSource) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BehaviorDesigner.Runtime.Behavior.CheckForSerialization () (at <42c6db9471014bf4aea7a71e269af019>:0)
    BehaviorDesigner.Runtime.Behavior.DrawTaskGizmos (System.Boolean selected) (at <42c6db9471014bf4aea7a71e269af019>:0)
    BehaviorDesigner.Runtime.Behavior.OnDrawGizmos () (at <42c6db9471014bf4aea7a71e269af019>:0)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
    Last edited: May 4, 2018
  43. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    Are you you able to list the steps to reproduce from a fresh 2018.1 project? I just tried to reproduce this but wasn't able to.
     
  44. gusrbehfdl

    gusrbehfdl

    Joined:
    Jul 26, 2015
    Posts:
    1
    How can I get rid of these warnings ? :

    Script attached to 'BehaviorDesignerGlobalVariables' in scene '' is missing or no valid script is attached.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  45. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    It looks like the global variables asset file is missing its reference - you can reassign the GlobalVariables script reference to the BehaviorDesignerGlobalVariables.asset file.
     
  46. ilusomu

    ilusomu

    Joined:
    May 28, 2015
    Posts:
    24
    Hey folks! Just started using BD and have been really digging it. That said, I have run into a bit of a jam at the moment: I have a super basic animator and controller strapped to an agent that I have patrolling a small space with a waypoint pause duration set for five seconds. The agent's speed doesn't return to 0 during the pause, so the agent continues its walk animation while waiting and never idles. I feel like the solution to this is probably super obvious, but I can't seem to figure it out yet.
     
  47. Winseral

    Winseral

    Joined:
    Jul 9, 2017
    Posts:
    11
    Hi,

    I am new and have just purchased BD.

    Could you please supply some details on how to access ScriptableObjects within the Designer?

    I have PlayerHealth and EnemyHealth SO which I would like to allow the enemy to know the states of its health so it can flee when value reduces to 10% and play an enemy injured animation.

    Secondly, I have event systems that tell the NPC when day/night occurs and would like to use BD to change animations behaviour depending on time.

    Any help would be great, a video would be fantastic.
     
  48. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    You should structure your animator/character controller similar to this guide - this way the character will always use the NavMeshAgent's velocity (or equivalent pathfinding implementation):

    https://web.archive.org/web/20160317180801/http://mecwarriors.com/2014/12/09/navmesh-and-mecanim/
     
  49. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    4,680
    For performance reasons I recommend creating your own task that accesses the ScriptableObject/Component direction:

    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=5
    http://opsive.com/assets/BehaviorDesigner/documentation.php?id=10
    http://opsive.com/assets/BehaviorDesigner/videos.php?id=3

    You can also use the reflection tasks to access other components but it'll never be as quick as creating your own task for that purpose.
     
  50. g3tinmybelly

    g3tinmybelly

    Joined:
    Jul 5, 2014
    Posts:
    6
    So I saw that you have networking support in Behavior Designer using Unity's networking solution but was wondering if you plan on integrating with Forge Networking as well?