Hi Everyone! Still a bit of a novice when it comes to Behavior Trees.
I’m having a weird issue that no amount of research or testing has yet to fix. I’m running a Behavior Tree on my AI where they search for a next available node on a path and then move towards it. I run a task where I do three ForEachofLoops to find the three nearest potential node points and then randomly select one to be the target.
Everything worked as expected with one AI running the behavior tree on the map. But as soon as I add more AI, issues crop up.
Here is the Behavior Tree running. Notice that the “NextNode” Key, which is the target of Move To, is properly set as an object.
When multiple AI are running this behavior tree the “Move To” task runs for one frame, then goes back to the Task_PeonFindNextNode to select another target NextNode. It then runs Move To for just a frame again, and repeats this whole process. It executes like the Move To target is null or the AI can’t move, despite the fact that the key has a valid target and the AI is unobstructed.
Here is where issues crop up that I can’t figure out. Eventually, the AI gets out of the loop and properly moves to its NextNode target. The more AI characters there are on the map running this behavior tree, the longer an AI will stay in that loop. If its five AI, it may loop 20 times before fixing itself. If its fifty AI, it may loop 100 times. This REALLY kills performance.
Is there some basic concept about multiple AI running the same Behavior Tree that would cause this? Any other suggestions?
–
Janky Fix: I found that if instead of using “Move To” in the Behavior Tree, I use a blueprint task with “AI Move To” towards the NextNode, the bug is gone. Probably because that task can’t be aborted until “AI Move To” is completed. But I know you’re supposed to use “Move To” in a Behavior Tree. And it makes it easier for me to check for abort behaviors on game updates. I’d prefer to find a better proper fix.