Manual tick behaviour tree problem

Nenad

New member
Hi,

I have a problem when I try to tick behavior tree manually.

BehaviorManager.instance.Tick(_allEnemies[index]);

The error that I have is

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[BehaviorDesigner.Runtime.Behavior,BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree].get_Item (BehaviorDesigner.Runtime.Behavior key) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:150)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.Behavior

When I debug my code I can see that BehaviorManager.instance have only one BehaviourTree but I don't know why. Does anybody know how BehaviorManager.instance is collecting BehaviourTries and what could I do wrong to get this error.

I have two agents on this scene and for both of them I load and instantiate behaviours manually

ExternalBehavior tmpExternalTree = Object.Instantiate(externalBehavior);
tmpExternalTree.Init();
UnusedBehaviours.Push(tmpExternalTree);
 

Attachments

  • error.jpg
    error.jpg
    119.2 KB · Views: 2
After some investigation I find problem and solution. My BehaviorManager.instance was null at time of seting up manually ExternalBehaviour.

Make sure that BehaviorManager.instance is initialized before call

behaviorTree.DisableBehavior();
behaviorTree.ExternalBehavior = externalPool[index];
behaviorTree.EnableBehavior();

This can be done with adding BehaviorManager in script execution order.
 
Top