libgdx / gdx-ai

Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Apache License 2.0
1.2k stars 242 forks source link

Behavior trees Parallel components clearing Sequences #132

Open SamuraiJones0 opened 12 months ago

SamuraiJones0 commented 12 months ago

I believe this is a dead library, so I'm writing this more for other devs who might stumble on this issue, but I'd be thrilled if it was to get fixed. I'm using the 1.8.2 version of gdx-ai (latest version as of now).

I've found the problem in the library... and while there's a simple obvious fix to solve for my configuration, I'm unsure if it'd break other configurations.

My issue presents as my tree running once and then freezing up.... subsequent Tree.step() calls appear to do nothing.

I'm setting my trees up using parser with the external .btree file. My Behavior tree appears like so: (I'm not including paths or detailed descriptions of my leafs as that's unimportant):

root sequence parallel policy:"Sequence" orchestrator:"Join" cooldown sequence getTarget Range:10 rotateToTarget Range:10 RotateSpeed:360 turretShootLeaf

(I'll include this as a screenshot so indents show up) image

It appears that when the parallel task has its first success, it resets all its children. (com/badlogic/gdx/ai/btree/branch/Parallel.java line 223). However, when the inner sequence is reset though, it removes all children (com/badlogic/gdx/ai/btree/BranchTask.java, line 76). Children never get re-added.

In the debugger pics below, you can see that on the first pass, the sequence contains the two leafs. In the 2nd pic, you can see the sequence about to clear its children. In the 3rd pic, you can see that on the 2nd run, that task has no children.

image

image

image

So to summarize, in my app after the parallel task succeeds, the inner sequence's children (getTarget & rotateToTarget) are removed, and thus my inner sequence has no children, and thus tree.step() does nothing. As a workaround, I'm going to suggest that sequences (and probably other task that subclasses off BranchTask) never live nested directly under a parallel task.