Behavior Tree Woes!

Hello, after days of nearly going crazy with Behavior Trees i decided its best to post here :slight_smile:

Anyway. All the behavior and functionality im trying to achieve is for a Simulation game, clearing that out of the way so its easier to understand later on

Im trying to create a behavior tree for my Customers ( Simple AI Bots with a character and AI Controller class ) in which they will:

Once Spawned go to the tavern, Try to find a available seat, if found go to said seat and then order a drink and do absolutly nothing else

If no seat was found, randomly wander in the tavern and eventually engage on a fight with a customer that has a seat

I got all the code and tasks written down but my main issue is with the layout of the tree itself . and So i currently have my Behavior Tree like this

Not the cleanest but so far its mostly working, Once a customer is spawned it runs the Move To The Tavern and wander sequence ( Set blackboard key , move to said blackboard key vector, random chance to wander)

Then Take a seat and order a drink is called since the sequence was succesfull (Get avaiable seat, if succesful move to it and order a drink, else fail the sequence and move into Wander and try to pick a fight )

Now this is functional up until i want my pawn to leave the Wander and try to pick a fight sequence, since when a fight has ended the pawn is still looping on the Wander and try to pick a fight sequence, Also i had to loop this sequence once the player enters becouse if not when BTTask_TryToPickAFight has ended it “fails back” to the selector .

Essentialy im trying to lock the Customer into the Wander and Try to pick a fight sequence when certain conditions are met (Doesnt has a seat, cant find an available one ) and Force him out of said sequence when other conditions are met (If a seat is available, go to the take a seat and order drink sequence )

I tried using blackboards, services etc but i still cant nail a right layout for my tree. Closest i got to a “Only go trough this sequence if X is met” was using a blackboard decorator and abort my sequence if the condition wasnt met instead of just "Dont go trough here "

Any help is always appreciated!

when i see it, i think it’s best if you set some kind of flags(using decorator) on the “take a seat and order drink” selector and also in the “wander and try to pick a fight” selector. and make it like a fsm. so your BT can be more manageable, and also you can determine which state you are in, and which condition that makes you leave that state… (don’t need loop decorator at all)

You don’t have enough conditions on your selectors. Specifically, you should have a “is seat available” decorator that aborts lower if it becomes true. You might want to have another decorator on that case for “is currently seated” and one for “is currently fighting” etc. Basically the decorators should form a set of criteria for running the sequence. The key point being that priority of the selector runs left to right. So put your most important behaviors on the left. Then work out the decorators that must all be true for that sequence to be correctly selected, finally make them abort lower priority sequences when they are true.

They key is to think of the conditionality for a sequence. Don’t think of it as state (as a previous comment suggested, I think thats a bad plan for BT’s) but instead think of it as a checklist.

Keep at it though, it does get more natural as you work with it.