Problem with setting up a sequence with all mandatory task when some returning TaskStatus.Running

SXtheOne

New member
Hi,

I've made my own tasks and I have my first working Turret AI but I feel I'm missing some important understanding of how things work in Behavior Designer (I also watched all the tutorials). Specifically I have problems with tasks returnning TaskStatus.Running while they are working. If I have a Sequence with several tasks and one of the tasks returns Running for a while, all the other tasks are waiting, nothing gets executed until the Running task finishes. How to get over this the proper way?
I think I would need something like the Selector Evaluator but for Sequences. I can write one for myself but I have a strong suspicion that I'm missing a point here because my case is nothing special and should be able to make it work with the combination of basic tasks.

So, again, with different wording: the problem is that when I have a sequence where I need ALL the tasks to run in every tick when the sequence is evaluated, a task which returns TaskStatus.Running ruins everything (the other tasks won't run until this one finishes). How can I make this work, what is the proper way of doing this?
 
You can use a Parallel task for this use case.
Thanks for the answer. I tried the parallel earlier, but am not certain in an aspect of it. Is parallel starting the tasks in the same order everytime even when a task returns Running state?
 
I watched that video but I think this is the part where I'm confused. I mean there are OnUpdate calls in basically every task where the task does something. One sets a variable, other one uses it (and that's the one what returns Running). I guess there is a loop inside behavior tree's core which goes through these task update methods in sequence if it is a Sequence task, right? If not, how is it handled?

The second question is the same but for Parallel. Is Parallel starts threads for every task? Or it won't start threads and its not really parallel? I haven't checked out Parallel's code yet if threads are getting started there or not.

The third question comes from the second: if parallel starts threads how can it guarantee to run the update methods to run in order every time? I'm not pro in multithreading but making the threads waiting just to be able to run them in a certain sequence would kill the reason for multithreading, doesn't it?
Thanks for the explanations!
 
Oh, one more thing. In the video when the sequence task runs once it won't be started again and I need to get run all the subtasks in every frame because I need to update variables in a certain order.
 
I mean there are OnUpdate calls in basically every task where the task does something. One sets a variable, other one uses it (and that's the one what returns Running). I guess there is a loop inside behavior tree's core which goes through these task update methods in sequence if it is a Sequence task, right? If not, how is it handled?
The sequence task keeps an index indicating its position within all of the children. The return status isn't stored anywhere, it's just used to determine if the tree should progress to the next task.

The second question is the same but for Parallel. Is Parallel starts threads for every task? Or it won't start threads and its not really parallel? I haven't checked out Parallel's code yet if threads are getting started there or not.
Technically you're right in that it's not threaded so it's not a true parallel, but all of the children are run during the same update.

The third question comes from the second: if parallel starts threads how can it guarantee to run the update methods to run in order every time? I'm not pro in multithreading but making the threads waiting just to be able to run them in a certain sequence would kill the reason for multithreading, doesn't it?
Thanks for the explanations!
No thread is used but the children in the parallel task will run from left to right.
 
So if I need a similar task like Selector Evaluator but for Sequence, I need to implement it myself, right? Because the Parallel doesn't run the successful task again until the longest running task finishes.

Also, are the tasks under a Sequence gets executed in the same frame? It can be important and would save me some time if I don't have to measure it myself.
 
So if I need a similar task like Selector Evaluator but for Sequence, I need to implement it myself, right? Because the Parallel doesn't run the successful task again until the longest running task finishes.
There is a Parallel Selector or Parallel Complete task as well. But beyond that you'll need to create your own task.

Also, are the tasks under a Sequence gets executed in the same frame? It can be important and would save me some time if I don't have to measure it myself.
It will be as long as a child task doesn't return a status of running.
 
Top