Decorator not aborting composite node as expected in Behavior Tree

I’m encountering unexpected behavior trying to use decorators on my BehaviorTree.
The Blackboard attached to my tree has one key: a boolean called ‘ShouldStop’.
The task that it runs (BTT_InterruptMePlz) just counts down from 5 on each tick until it hits 0, at which point it sets the value of ‘ShouldStop’ to ‘true’. It also prints out the value of ‘ShouldStop’ each tick so that I can check it’s being set properly.

I’ve attached a decorator to the Sequence node node above the Task that checks that ShouldStop is not set. I’ve set its ObserverAborts to ‘Both’ (I’ve also played around with all the other settings). However, when I run the game, BTT_InterruptMePlz is never aborted.

However, if I attach the same decorator to the actual task node, it does work.

The reason I want to be able to use a decorator to check a boolean on a Sequence node is: I want to create a BehaviorTree that pauses all operations and starts again when a bool called ‘IsStunned’ is set to true, so that any task being run such as rotation or pathfinding will be interrupted when that happens. In other words, I’d have a sequence right under the root of the tree with a decorator on it checking that ‘IsStunned’ is not set.

My impression was that a blackboard-key-check decorator would be notified whenever the key it’s watching is changed, and that if its ‘observer abort’ setting was set to ‘self’ or ‘both’ any tasks underneath it would be aborted.

If this is not the case, can anyone tell me how I can achieve this? Thank you!

If you mouse over the decorator in your first image, you can read that it says that top level decorators don’t work, and will only work if the tree is executed as part of a Run Subtree task in another tree
If you want to cheat it you can just add another sequence right above your sequence and add your decorator to the second level sequence, and it should work just fine. Otherwise, you can also call Stop Logic on the brain component in your AI controller to stop the logic, and then start it again later

2 Likes

Thank you so much, I completely missed the little ‘Oh hey this doesn’t work’ message. This absolutely saved me.

Does anyone know why it’s set up like this? I’m kind of baffled, because surely the thing I’m trying to do - getting the behavior tree to essentially ‘reset’ by jumping right back onto the top when the AI is interrupted by something like a stun effect - is something that comes up, like, ALL THE TIME?

Tbh I’ve found getting started with AI in Unreal really frustrating: I wish that the documentation went into some detail about why things are set up the way they are instead of just giving you this really abstract description of what a behavior tree is etc. I mean, I don’t know if AI is being run on a separate thread, how often it ‘ticks’, and I’ve come across all kinds of weird and wonderful bugs like needing to delay running the behavior tree in the first place because sometimes the AI Controller freaks out if I just do it from BeginPlay. Yeah, I’ll look this stuff up, but I feel like Epic should be jumping up and down to tell me so that I have a good time using the engine.

AI is something that relative beginners like me have to deal with pretty early on, but the AI team doesn’t seem at all concerned with communicating with the community. Maybe they’re expecting Youtube vids to fill in the gaps but the stuff that’s out there is pretty shallow: just a lot of ‘EaSY Ai PAthFINDinG in 5 mINUTES’ stuff. Sorry for rant, but I don’t get the point of creating all of these really elaborate systems and then not having someone write down in a slightly discursive way what’s actually happening under the hood and how you should use them.