Make BTTask continue in time

Hello, sorry for the silly question.

How to I make a BTTask continue in time until a specific condition is met?
All the tasks I’m creating require the “Finish Execute” node but core tasks like Move To and Wait can continue execution for multiple ticks.

Thank you

1 Like

From the top of my head i can think of at least two solutions to your problems.

  1. What Matthias Hölzl said. You dont have to come out of the Task unless you feel you acheived (or failed) what it is you wanted. You can do checks inside the task and when you want the task to complete you can simply return FinishExecute with either True or False.

  2. You can add a service to that task node (or to a selector above it) checking condition again and again. If condition is not met yet, you can keep running task. if it is met, mark “Abort self” and it will abort itself and move to a different node.

Thats what i would do.

i might not understand the problem correctly. if i didnt, let me know and ill try to help more.

All the best :slight_smile:

There is an example how to implement a Move To task in the Behavior Tree Quick Start. The main idea behind long-running tasks is that you return normally while the task is still active and call Finish Execute only when the whole task is finished.

By return normally you mean just no Finish Execute unless condition is met?
I tried to do something like this (before posting) with a simple random int (0-10) printed on screen, if the int is lower than 2 then call finish execute.
Only one int was printed and the BT got stuck there.

I’m trying to tell an enemy AI to chase the closest character (there are 4).
I have a service that selects the closest one and put its reference in the BB.
A Move To task that moves towards the actor with a decorator killing it if the target changes. The problem is that it skips a frame (which is an expected behaviour) and the animation is not fluid.

Now, the Move To explained in the behaviour tree quick start should work but i’d like to understand what allows a task to continue running and recreate something like that without a core function taking control of the flow.

As far as I understood a task gets called every tick (because services and decorators above are). If it can “continue” then only its direct parents are called.
Problem is Finish execute failure/success is for selectors and no finish execute blocks the BT execution

OK, I probably wasn’t very clear: You only call Finish Execute once the task is really finished (either successfully or unsuccessfully). But Receive Execute is only called once, when the node starts execution. If you want to have a long-running task do something (without calling a latent function in Receive Execute) you need to implement a Receive Tick event as well. Something like this:

(Please excuse the messy Blueprint.) Here the event Receive Execute only sets up the values, the actual movement is then performed by Receive Tick. The Finish Execute function is only called once the actor is close to its target location. (This movement function is really bad, because it does not animate the actor, etc., but hopefully it illustrates the point.)

1 Like

Perfect, that’s exactly what I need!
I didn’t know I can have multiple events inside a task but it perfectly makes sense!
Thank you again