Updating ExternalBehaviors on a BehaviorTreeReference


New member
I am trying in a manual loop to update the externalBehavior of the next node. For example in the update of a conditional node I am running this, but I am hitting an out of range exception :

        public override BehaviorDesigner.Runtime.Tasks.TaskStatus OnUpdate()
            if (treeGenerator == null)
                treeGenerator = GameObject.FindObjectOfType<GiveMeTree>();

            dest = treeGenerator.GetRandomPos();
            var randomVal = UnityEngine.Object.Instantiate(treeGenerator.GetTree());

            reference.externalBehaviors = new ExternalBehavior[] { randomVal };

            return BehaviorDesigner.Runtime.Tasks.TaskStatus.Success;


What I want is to have a set of purposes stored as external behaviors in a core agent manager, who will monitor the requirements update the available tasks.


New member
Ah apparently the whole tree is evaluated before it starts, so you need to either set this from an outside script.

However, even when it is restarted. or the tree is enabled/disabled the reference tree behavior is not reseted. Performance wise, should I be marking the root of the branch and replace it before each loop(which won't be very frequent)? or the initial state with the empty reference as an external behavior?
Last edited:


Staff member
As you saw, when the tree is started (or restarted) the Behavior Tree Reference task is consumed so there's no way to access it again. If you want the reference task to be available again the easiest way to do this would be to keep an external tree that has the entire setup, and then when you start the behavior tree you assign a copy of that tree. This will then restore the tree back to the original set of tasks.