Behaviour Tree doesn't act as expected when decorator placed on Service


I followed a tutorial on a basic AI that I wanted to expand on. The basic AI wandered the scene and would have a vision check that checked if the player was in the cone of vision. If yes, it would follow the player until reaching them (whilst constantly keeping a record of the players latest location), if no, it would wander, if no (and had a memory of the players last location) it would go there then start to wander.

It looks like this:

This worked. If the AI saw me it would go up to me and stop until I move away.

I didn’t want this ‘vision check’ service to be the main behaviour of the AI so put a decorator on it that checks another blackboard variable. When the variable is the correct one it should start the vision check behaviour. It looked like this:

This makes the AI go up to me and, instead of just stopping like it used to, it just starts awkwardly turning back and forth on the spot as it seems to be looping through the three sequences under vision check. It goes up to me, turns away for some reason, then instantly turns to go to the memory of my last location even though it sees me, then turns away instantly etc.

I guess this is a result of the vision check behaviour being rerun unlike how it was before or something. I’m new to behaviour trees so any help with this is appreciated.



Putting a decorator on the top of the service and nothing after it on the selector (below the root) means that as soon as the AI awareness is equal to anything but “On Quest” it will abort the entire tree below it and since you have no second option for it if this is the case, it probably gets into some weird loop and does nothing.