How to interrupt a Behavior Tree's processing?

Sorry for the beginner question.
I’m trying to make a simple AI that will shoot when an enemy is in range and stop when it’s out of range. But the shooting doesn’t stop even if the enemy moves out of range.
I tried decorators because I heard they work like branches, but changing the Boolean value doesn’t change anything.
I attach a picture of the process.Can someone help me?



Hi,

Hope you’re doing well.

Ok, we can handle that in a couple of ways.

The easeast way is make use of that blackboard decorator on the sequence node instead of your task none. So you will only aim and fire if your target is in range.

So on your WeaponFire you can make use of the loop node, so you can have some shots in loop (e.g. 3 times) and the process will start over again.

By the way, where are you updating that variable Is In Range?

You can make use the Behavior Tree Services Node

Hope that helps - take care!

Thanks for replying quickly!
Yes, the variable that checks if the enemy is within range is InRange.
Does the decorator’s place matter? The only one that requires a condition is WeaponFire, so I put it there. I don’t want AimTo to be blocked.

Yeah,

It matters a lot.

Don’t worry, you are using a sequence node, which means all nodes inside it is going to ro run.

I got the idea, but I didn’t see any service node inside your behavior tree, so where are you updading that variable? How to you know if it true or false?

The value is set by SetValueAsBool in the AimTo task. Is this not working properly?

It may work.

Look this reference node:
Behavior Tree Node Reference: Composites

But It will be updated only when AimTo task is running, in other hand, if you add that check to the sequence, it will update while the sequence is on.

By the way, did you make it work?

It worked in the end.
The problem was that when WeaponFire was executed, the AimTo task was finished, so the evaluation of InRanged was finished.
When AimTo is run on Tick, it will continue to evaluate, allowing the tree flow to work.

I think it was a rookie mistake. But I learned a lot from your reply. Thank you for your help!

1 Like