Moving Closer Optimization in Behavior Tree

So I’m taking another pass through my behavior trees to try and speed them up. One area I would like to make more efficient is my “move into range” task. Here, I use a Tick to see if my status switches to idle (which should only happen if I am in range) and then change my state to attack.

Given that behavior trees are an event driven system, I feel that this tick is a hack and should be removed. I’d like to prevent a tick in a task if I can. My initial thought is to create a service checking range to target rather than having this tick but that’s still essentially polling rather than an event driven approach.

I’m not sure if the thing you are looking for is my answer, but I usually do the state checking inside my enemy blueprint, which probably not the best way, but this totally depends on the form of AI. Hope this helped.

As far as I know, BehaviorTrees can only be driven by blackboard variables. Checking if I am close enough is fin and all, I just want it to not be in a tick. Ideal this would be done with an overlap or collision event but only with the target. This just has trouble altering the behavior tree if done from outside it.

Is the “range” known when you start your move? Why not use the engine-supplied BT tasks for movement, or BP AI Move To node that will notify you when AI reached the specified distance from the goal?

Cheers,

–mieszko

The range would be a variable and from what I can tell the default BT Task Move To does not allow you to plug in a variable or even a blackboard key for the Acceptable Radius. If I have it call a function from inside my task would it not “fire and forget” and just keep running my tree over and over again instead of having my leaf nodes doing work that takes time?

My understanding is that the nodes do not tick if they are “working” so it’s best practice to do it this way.

You could have a service executing logic for range checks and changing blackboard values that are observed by higher priority decorators.

You could make a custom decorator that does the range check and supports the event driven callbacks.

I have the first method working just fine as there are lots of situations where my AI may behave differently depending on how in range they are to their targets.

Yea the only problem is that a service is just a less frequent tick. I guess I’ll try to extend the move to task in c++ and expose a blackboard key for the range instead of a static number.

I’ve written tasks before so it should not be too big of a problem even if it’s as simple as copy and paste of the entire class with a few re-factors here and there while converting the blackboard key to a float.