Receiving Stack Overflow issue with Column Formation


New member

Hi there,

I got an error with my behavior tree, and don't know what to do.
Above you'll find a part of my behavior tree.

At the end you'll see a screenshot of the error message.
(StackOverflowException: The requested operation caused a stack overflow.)

What is causing the problem?
* The column (highlighted in tree above) task for every npc except the one which is marked as the leader.

Here's how the column task was setup

The NPCs are generated when I click play by a custom script. Basically leader and "followers" are based on the same prefab.

Here you can see the variables used for the leader, after initialization:

An here are the variables used for the followers, after initialization:

What I want to achieve is basically, when the variable "CurrentCommand" shows Hold, the NPCs should create a column formation at the given transform in the variable "HoldPositionTarget".

The Error I'm receiving can be checked in the following screenshot.2018-11-14_15h22_50.png


  • BehaviorScreenshot.png
    259.6 KB · Views: 3
  • BehaviorScreenshot.png
    259.6 KB · Views: 7
Hmm.. are you able to create a small repro project that I can debug? If you can send me a link via PM that would be great.
Hi, thanks for looking into it. Here's the link to the git repo on Bitbucket. It's not the whole Unity Project, because I have quite some assets in there. But I did some modifications to the scripts (notable by the word "simple" behind them), so you don't have to worry about the dependencies. Also note that I own the Movement, Formations and of course the base package of Behavior Tree, which is also not present in that repo.

Thanks for the scene. I had to remove the original non-simple scripts in order for it to compile but it now imports without any errors.

How can I reproduce the issue within the sample scene? I don't get any errors when I hit play.
Hi, sorry I wasn't testing the export properly. I just created a new project from the package and fixed the compiling issues. It should work now and show the error message. Note that I basically threw out everything from the behavior tree, that would cause an issue because of missing assets, so don't wonder if some branches don't make sense.
I made a new commit in the repo.

The Behavior Designer Assets still have to be imported separately. ;)
Last edited:
Thanks - that worked. It looks like the column task for your leader agent also specifies the leader. For this task make sure the leader is null so the column task won't try to add itself to the group.
Thanks for looking into it, but I don't really get it. Does the Column Task find itself a leader with agents of the same "Group"? As you can see in the screenshots above the leader has its leader variable set to "none", while the other agents have the "Ally" GameObject assigned, which is the GameObject that has the variable "Leader" with the value none. Also in the example script the behavior should be like this.
How are variables handled? As you saw I'm using one external Behavior Tree for multiple agents. Are variable values synchronized between every agent that uses the same external behavior tree? Could that cause the issue if I want to set the "leader" variable for the first agent, it will also try to apply the same value to all other agents with the same external tree?
I didn't look into detail how the variables were being assigned, but when I clicked on the leader agent it had the leader variable filled in. If you are assigning the variable to an external tree before that tree is assigned to the object then the variable will persist across all of the trees. You'll want to only assign the leader variable after all of the agents have been created.
I did some additional research and I think I found another issue.
The stack overflow problem is gone as soon as I remove the "Attack" Tasks from the most right branches in the behavior tree. It seems like the OnAwake method is called for the Column and twice for the Attack Task, which each tries to add the agent to a group.