Behavior Tree tasks conflicts

I apologize if this is too long and general. Its just that I’ve been having a lot of issues with my behavior tree. What I want is for my AI to cycle through tasks such as 1>Scout player base 2>Visit a stream 3>Visit AI base 4>Explore 5>Return to AI base. At any time while the AI is performing a task I want it to cut out if it encounters an interruption such as 1>Sees a player 2>Sees a pig 3>Sees a coconut tree. In that hierarchical order, for example if AI sees a coconut tree and the player the AI will chase the player. After the interruption I want the AI to return to the task it currently was doing. Now for all the design issues.

One design I tried is going from the root to a main selector and then from there to multiple selectors which connected to my tasks and interruptions. The problem which arises is my AI would get stuck in an infinite loop doing the same task. I then tried going from the main selector to multiple selectors which went to multiple sequences. Once again my AI got stuck in an infinite loop. I tried many different configurations using both selectors and sequences and every time my AI would get stuck. In frustration, I decided to connect every sequence directly to my main selector. Finally, the AI was able to cycle through every task, and repeat.

But, I don’t like this setup. Its messy having every single sequence connect directly into my main selector. Instead of forming a hierarchical tree, my structure has become one long chain. I also am having to put a long list of black board conditions on each sequence. For example, my stream task has: AiDoStream is not set, CanSeePlayer is not set, Can see pig is not set, can see coconuts is not set. Plus, I’m having to create a unique variable which triggers true once the task is complete. If I don’t do this, every time the AI gets an interruption it will go back and redo every single task left to right regardless whether the task was completed or not. I’m literally having to force the flow backwards to sense interruptions. Which leads into a major challenge I’m having.

You would think nodes farther to the left would have higher precedence, and would go till completion and then the flow would work left to right. But, in actuality this is not the case. Some how my flow always finds a way to jump out of the interruption its currently on such as chase pig (which is farther to the left and higher precedence) and jump into a task such as FindStream. Then, it jumps back to chasing pig. And then back again. On the screen this is obvious cuz the AI will sort of freeze in place spazing out between the pig and stream. It will do this for about 30 seconds until eventually one task will override the other.

What I need is for the AI to do the interruption until completion, and then resume the next available task. I’ve tried all sorts of methods such as increasing the loop amount, setting a timer, restructuring the node structure. I’ve tried every possible setting in the observer aborts section. Nothing has worked.

My dilemma is I have to keep a task open so the AI can cycle through. Yet, I have to keep my interruptions open so the AI can be responsive. So, I don’t know if this is due to bad tree design or something else. I’ve been hammering away at this for the last 3 days and still haven’t found a workable solution. Any help, I’d greatly appreciate!!!

Hi, can’t really help you there, but it seems to me that you need to reorder/simplify your behavior tree. So maybe make a separate behavior tree for “Sees a player”, another one for “Sees a pig”, and so on. Then in your main behavior tree use the “Run Behavior” node to run those behavior trees. That might make it easier to read/maintain.

You would think nodes farther to the
left would have higher precedence, and
would go till completion and then the
flow would work left to right. But, in
actuality this is not the case.

That’s the case they execute from left to right, the reason you have those jumps would be in your code :slight_smile:

So you would need to debug your code, somewhere you have some logic that is not doing what you expect it to do.