Hi.
I have performance problems when switching External Behaviors on BehaviorTree component in runtime. There is a spike on EnableBehavior
Right now I have cut up one huge tree into smaller ones, cuz its clunky to debug and because editor can only handle so much.
So my npcs have like 5 types of behaviors that I would like, which are all seperated in external behaviors and there is more than one npc ofcourse.
I have a behaviorController script which does a bunch of things that are called each frame and really shouldn't be in a behavior tree as well as handling and switching external behaviors. It has a reference to the BehaviorTree component and it also has a pool of external Behaviors.
Right now each npc creates his own pool of External Behaviors that it can use and switches them when they should in run time by disabling Behavior Tree, setting external behavior and enabling back. Same as in documentation example.
As far as I can tell when I'm Enabling the BehaviorTree, it basically itirates through all the node structure again, even though I Instantiated External Behavior b4 hand.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm thinking of pooling BehaviorTrees instead of External Behaviors. Would that work? Is it possible? Would it be more performant?
Did I go wrong about this? Should I just make gameObjects on npc prefab each with its own BehaviorTree component and then have behaviorController script pause/restart/start them based on my internal logic? But when the behaviorTree is paused and enabled again, it calls EnableBehavior again and iterating through whole node structure again, thus I achieve nothing by this? or no? If paused and resumed it will also call all OnAwake functions again? or no?
What exactly is in BehaviorSource? Node structure? Could I just pool that? Could I just directly set BehaviorSource? That pool could than be not just for an instance of npc, but for all npcs that use certain type of behavior --> thus certain type of node structure, but possibly each with different vars values that would need to be set on behavior switch or actually just read in runtime from my behaviorController script, since I don't use sharedVariables.
Does any of this makes sense or am I just confused?
Actually, my question is: how to approach this problem?
Also right now, I'm not pooling npcs prefabs, because I'm not worried about onStart spike, yet. Because of project workflow, it will be added later. I'm just worried about changing behavior spike for now.
I also tried checking the asynch load checkbox, but it gives me an error: An item with the same key has already been added. Key: "name of the behavior I set on start"
Thank you
I have performance problems when switching External Behaviors on BehaviorTree component in runtime. There is a spike on EnableBehavior
Right now I have cut up one huge tree into smaller ones, cuz its clunky to debug and because editor can only handle so much.
So my npcs have like 5 types of behaviors that I would like, which are all seperated in external behaviors and there is more than one npc ofcourse.
I have a behaviorController script which does a bunch of things that are called each frame and really shouldn't be in a behavior tree as well as handling and switching external behaviors. It has a reference to the BehaviorTree component and it also has a pool of external Behaviors.
Right now each npc creates his own pool of External Behaviors that it can use and switches them when they should in run time by disabling Behavior Tree, setting external behavior and enabling back. Same as in documentation example.
As far as I can tell when I'm Enabling the BehaviorTree, it basically itirates through all the node structure again, even though I Instantiated External Behavior b4 hand.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
I'm thinking of pooling BehaviorTrees instead of External Behaviors. Would that work? Is it possible? Would it be more performant?
Did I go wrong about this? Should I just make gameObjects on npc prefab each with its own BehaviorTree component and then have behaviorController script pause/restart/start them based on my internal logic? But when the behaviorTree is paused and enabled again, it calls EnableBehavior again and iterating through whole node structure again, thus I achieve nothing by this? or no? If paused and resumed it will also call all OnAwake functions again? or no?
What exactly is in BehaviorSource? Node structure? Could I just pool that? Could I just directly set BehaviorSource? That pool could than be not just for an instance of npc, but for all npcs that use certain type of behavior --> thus certain type of node structure, but possibly each with different vars values that would need to be set on behavior switch or actually just read in runtime from my behaviorController script, since I don't use sharedVariables.
Does any of this makes sense or am I just confused?
Actually, my question is: how to approach this problem?
Also right now, I'm not pooling npcs prefabs, because I'm not worried about onStart spike, yet. Because of project workflow, it will be added later. I'm just worried about changing behavior spike for now.
I also tried checking the asynch load checkbox, but it gives me an error: An item with the same key has already been added. Key: "name of the behavior I set on start"
Thank you