Spike occurring when enabling and setting a value in behavior tree?

We spawn Gameobjects with Behaviour Tree components linked to External behavior Trees using a pooling system. These objects are reused. On startup of an agent behavior tree, we immediately set the value. When this happens we receive a large spike. When the behavior trees are used a second time or any time after, the spike does not occur.

Sample of some our code:

agentBehaviorTree = GetComponent<BehaviorTree>();
agentBehaviorTree.EnableBehavior();
BehaviorManager.instance.RestartBehavior(agentBehaviorTree);
_agentbehaviorTree.SetVariableValue("Agent", this);

When we set the agentBehaviorTree, we also set the variable value in that behavior tree. This seems to be an expensive task that is triggering the spike. The below shows the stats with spawning only one 1 enemy.

capture.PNG
 
If I have 3 chars using BT-A and 5 chars using BT-B do I need to pool 8 trees? 3 of BT-A and 5 of BT-B or is it 2 trees, 1 BT-A and 1 BT-B? Does each char need its own instance of a tree? This is if all the chars are in the scene at once. Can I have a pool of only 4 trees if all the chars in my level use one of them.
 
If I have 3 chars using BT-A and 5 chars using BT-B do I need to pool 8 trees?
You'll pool at least 3 instances of BT-A and 5 instances of BT-B. When you place the serialized tree back into the pool the tree will be reused when it is retrieved again.
 
Top