Getting a StackOverflow error on Tactical Pack

Hedwynn

New member
I've been trying to get the "Surround" task in particular working. There have been a few hiccups, but I believe I have resolved some of the issues. Now the biggest issue I seem to be having is I'm getting a StackOverflow error when I'm trying to determine the leader. I'm currently using:

Unity Version 2019.4.33f1
BD ver. 1.7.2
Tactical Pack ver. 1.3.1

Had to shorten it a little because it just kept repeating and could not copy/past the whole thing without going over the text limit.
C#:
StackOverflowException: The requested operation caused a stack overflow.
UnityEngine.Object.CompareBaseObjects (UnityEngine.Object lhs, UnityEngine.Object rhs) <0x23cebb0ba20 + 0x00037> in <e395ed1557354db1a729173c553a159b>:0
UnityEngine.Object.op_Equality (UnityEngine.Object x, UnityEngine.Object y) (at <e395ed1557354db1a729173c553a159b>:0)
BehaviorDesigner.Runtime.Tactical.Tasks.TacticalGroup.AddAgentToGroup (BehaviorDesigner.Runtime.Behavior agent, System.Int32 index) (at Assets/Behavior Designer Tactical/Scripts/TacticalGroup.cs:194)
BehaviorDesigner.Runtime.Tactical.Tasks.NavMeshTacticalGroup.AddAgentToGroup (BehaviorDesigner.Runtime.Behavior agent, System.Int32 index) (at Assets/Behavior Designer Tactical/Scripts/Tasks/NavMeshTacticalGroup.cs:113)
BehaviorDesigner.Runtime.Tactical.Tasks.Surround.AddAgentToGroup (BehaviorDesigner.Runtime.Behavior agent, System.Int32 index) (at Assets/Behavior Designer Tactical/Scripts/Tasks/Surround.cs:29)
BehaviorDesigner.Runtime.Behavior.SendEvent[T,U] (System.String name, T arg1, U arg2) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.Tactical.Tasks.TacticalGroup.AddAgentToGroup (BehaviorDesigner.Runtime.Behavior agent, System.Int32 index) (at Assets/Behavior Designer Tactical/Scripts/TacticalGroup.cs:202)

I also tried removing the check to see who is the leader and just ran each agent with the leader variable set to the leader from "Find" and it provides me with a nullreference error.
C#:
NullReferenceException: Object reference not set to an instance of an object
BehaviorDesigner.Runtime.Tactical.Tasks.Surround.OnUpdate () (at Assets/Behavior Designer Tactical/Scripts/Tasks/Surround.cs:70)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunParentTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32& stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus status) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at <3ed82e893f584901a16bc2e097c74b57>:0)
BehaviorDesigner.Runtime.BehaviorManager+<CoroutineUpdate>c__Iterator1.MoveNext () (at <3ed82e893f584901a16bc2e097c74b57>:0)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <e395ed1557354db1a729173c553a159b>:0)

Finally, I tried running all of the agents with the leader variable set to null and just each using themselves as a leader and got a LITTLE closer. They first sort of run from the bear (Which I'm assuming is trying to get to surround distance? - Just double checked and reduced the radius and this does seem to be the case.) then come back in to get in attack range. They are calling attack and everything fine, but they are kinda jittery, and if they aren't looking at the target, they rotate towards it very jittery as well.
Here is the behavior tree that I am using for this section. As of right now, it should be finding a game object with a specific name (Method will probably change a bit once I get this figured out, but just setting it from there was enough to get it going.) Then it checks to see if the current object is the leader and, if it is, runs the Surround task without a leader. If it is not the leader, it runs the next branch with the leader variable that was set by "Find" as the leader.



1640635762972.png
 
I'm not sure how you would get a stack overflow on that line but have you tried simplifying your tree to narrow it down? For example instead of setting the leader dynamically what if you set it manually just to get it working?
 
So something weird happened and all the tasks on my base behavior tree disappeared, so it was easy to at least test this. On the upside, it seems like the testing has potentially narrowed down the problem a bit? I tried to do it with just the Surround task on two different behaviors (The specific leader and specific followers) and the "Find leader" worked fine. The issue seems to stem from checking to see if the agent is a leader or not with a bool check and running a different tree based on that. Even having the branch disabled causes the StackOverflow error in the OP. 1640727787349.png
But once I remove it completely, everything works. Then the issue becomes that jittering rotation and standing still. Here's the surround when I have only the surround and find tasks.
Animated GIF


And here is the follower tree
1640728058241.png
 
Are you using root motion? That rotation is weird as it doesn't look like it's just on the vertical axis.
 
Double checked the models and the animations and they are not using root motion, but yeah, I checked the Transform and they are rotating on the X axis as well.

I expanded that follower tree to do another set of checks and swapped out the leader's separate behavior (That only had the Surround task) with this tree so that I can have them checking to see if they are a leader and, if so, run the Surround task without a leader, or if they aren't, find the leader and then surround with him. They find the leader just fine and the sharedGameObject is set no problem. The issue with this tree seems to be the NullReferenceException error that was in the OP at Assets/Behavior Designer Tactical/Scripts/Tasks/Surround.cs:70).

I found another thread with a similar issue and tried to set the followers to wait a second before starting the surround behavior (Which still causes the NRE) and tried deactivating them and reactivating them after hitting play and the leader already started surrounding the bear. That either causes a stackoverflow in the OP or just completely crashes Unity.
 

Attachments

  • Capture.PNG
    Capture.PNG
    38 KB · Views: 3
With the tree put into the behavior for the demo and modified for it (Namely changing the tree index to 7 and the tag to Player for the target to match the preview and I still get the stackoverflow or crash Unity
 
Can you list it out step by step? I'm unsure what field I set the 7 on and which Behavior Tree needs to be set to Player. Agent 0 is the leader and the rest of the agents are following. Did you change it just on the leader?
 
Top