# Parallel Execution in Behavior Tree

**URL:** <https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740>\
**Category:** AI\
**Tags:** Behavior-Tree, task, unreal-engine, question\
**Created:** [December 7, 2015, 11:09am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740 "2015-12-07T11:09:16Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_4030fea0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4030fea0](https://forums.unrealengine.com/u/anonymous_user_4030fea0)\
**Post date:** [December 7, 2015, 11:09am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/1 "2015-12-07T11:09:16Z")

</div>

Hi guys

I am creating a simple behavior for a cannon.

**The desired behavior is:**

1. Aim the cannon at the player, and simultaneously
2. Fire and Reload on cool down.

**I currently have the following Behavior Tree implemented:**

![69592-bt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/a/4/da4911e13dff4e5ab563b66b3232e0f2960c7d3b.png)

Predictably, this results in sequential execution of **Aim** , **Fire** and **Reload**.  
This causes rather ‘jerky’ behavior for the cannon since Reload task has a certain delay built into it.

How do I modify this to achieve the desired behavior? I want it to constantly run **Aim** task and **Fire & Reload** when these abilities come off cool down.

Thanks for your help

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_4030fea0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_4030fea0](https://forums.unrealengine.com/u/anonymous_user_4030fea0)\
**Post date:** [December 10, 2015, 12:10pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/2 "2015-12-10T12:10:39Z")

</div>

Ok - after spending 2 nights bashing my head on the wall. I finally worked it out.  
I tried **Simple Parallel** composite but I could not get it to work. For some reason it would always run the main task but it would **never** run the other tree. Here is the working Behavior Tree:

 ![70031-simple+parallel+bt.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/8/0b83959d8d1faeb14c0ca777e1d2b4a0767d9449.png)

When I tried this before, it would only run **Aim** task and never run **Fire** and **Reload**.  
The reason for that behavior is very subtle. From the [documentation][2]: _You can think of the Simple Parallel node as “While doing A, do B as well.”_

The reason why it did not work for me before is because I had **Finish Execute** node in the Aim Task. As a consequence, it would finish Aim when conditions were met and never execute the **Fire** and **Reload** sequence. Simple Parallel only works if the **primary task does not finish**.

This is not very obvious guys - could we please make it a little clearer in the documentation?

Thank you

---

<div class="post-metadata">

**Author:** ![SVR33](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/svr33/32/906589_2.png) [@SVR33](https://forums.unrealengine.com/u/SVR33)\
**Post date:** [April 7, 2016, 7:01pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/3 "2016-04-07T19:01:30Z")

</div>

Thanks, for this, Nick! You saved me from pulling out what’s left of my hair.

---

<div class="post-metadata">

**Author:** ![sonnyday](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@sonnyday](https://forums.unrealengine.com/u/sonnyday)\
**Post date:** [April 14, 2016, 6:06am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/4 "2016-04-14T06:06:26Z")

</div>

I signed in to applaud you, Nick Jackson, as i was having this same problem and not much documentation on it!!

---

<div class="post-metadata">

**Author:** ![E1andri1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@E1andri1](https://forums.unrealengine.com/u/E1andri1)\
**Post date:** [May 23, 2016, 8:50am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/5 "2016-05-23T08:50:02Z")

</div>

Hi,

I’m trying something similar.

I want to make an actor run around while shooting from time to time at a target.

 ![91569-graph.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/a/3/4a365d83d048ce75e4a4c6c9410f9d627e8ec960.png)

However, as soon as I attach my Fire Task the main task isn’t running anymore. It is running, though, if I add a Finish Execution node to the main task, but then the secondary task isn’t executed anymore.

**Are there any specific constraints on a secondary task?** My Fire Task so far is just a “Print Hello”-Node and the option of a finish execution node (doesn’t work no matter it’s connected or not)

If I connect the finish execution node in my primary task, the primary is executed like intended, but my secondary task isn’t executed anymore, as you have mentioned it.

Sorry, wanted to post as comment but I think, my image would vanish.

---

<div class="post-metadata">

**Author:** ![E1andri1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@E1andri1](https://forums.unrealengine.com/u/E1andri1)\
**Post date:** [May 23, 2016, 8:59am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/6 "2016-05-23T08:59:19Z")

</div>

okay, without the finish execute node, I assume, the primary task is executed only once, is that true? Do I need a while(true)-loop inside the task to keep it running?

---

<div class="post-metadata">

**Author:** ![E1andri1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@E1andri1](https://forums.unrealengine.com/u/E1andri1)\
**Post date:** [May 23, 2016, 9:00am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/7 "2016-05-23T09:00:36Z")

</div>

turns out, you can’t have a while(true) loop in a task as it throws an error.

---

<div class="post-metadata">

**Author:** ![KhalimWu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KhalimWu](https://forums.unrealengine.com/u/KhalimWu)\
**Post date:** [May 23, 2016, 3:44pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/8 "2016-05-23T15:44:43Z")

</div>

thanks, this made the note “finish with main task” more clear…now it makes sense. i was using simple parallel and wondering why the branch was never executing. had Finish Execute on the task too.

---

<div class="post-metadata">

**Author:** ![KhalimWu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KhalimWu](https://forums.unrealengine.com/u/KhalimWu)\
**Post date:** [May 23, 2016, 5:32pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/9 "2016-05-23T17:32:32Z")

</div>

Just started on AI days ago, so my approach might not be the best. I tested this tree. it will move to the Player Location and fire on sight, its a little more complicated than yours. Tell me if you run into any issue. Its important that you set the notify observer, that way it will work as a trigger and refresh the tree.  
If assume your waypoint picker is an roaming EQS, i would add that as a 2nd branch next to the simple parallel, so when it fails, the Pawn starts to roam around.

 ![91626-chasingfire.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/f/8/bf8a184dd528265c85c0fe1167e3cafbedc11f1b.jpeg)

 ![91627-eqs.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/f/a/cfa79a5362b70a32ea59e14934a463d94b267469.jpeg)

 ![91628-movetoplayer.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/1/e2135777c4b7351e7e1b85c7b0fe65b8e85a74db.jpeg)

 ![91629-firing.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/a/3/5a36947a570d573f92a703da2d9e93e2beb9696e.jpeg)

 ![91630-clearplayer.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/6/b/e6b96ab917949335744553953857571f5ed51d35.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fa5b3096](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fa5b3096](https://forums.unrealengine.com/u/anonymous_user_fa5b3096)\
**Post date:** [May 24, 2016, 1:34pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/10 "2016-05-24T13:34:51Z")

</div>

Have you tried making aim loop? Main task: sequence (with loop decorator) aim + maybe wait with a low time. Can make it loop indefinitely and if any other action is needed it can be forced out by an observer.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_fa5b3096](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_fa5b3096](https://forums.unrealengine.com/u/anonymous_user_fa5b3096)\
**Post date:** [May 24, 2016, 1:41pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/11 "2016-05-24T13:41:14Z")

</div>

You can have a loop decorator though.

---

<div class="post-metadata">

**Author:** ![E1andri1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@E1andri1](https://forums.unrealengine.com/u/E1andri1)\
**Post date:** [May 24, 2016, 10:11pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/12 "2016-05-24T22:11:53Z")

</div>

Okay, I gained some new insights on this:

your main task can indeed execute the Finish Execution node, however your simple parallel node needs its execution flow mode set to “wait for sub tree”

If it’s set so, then the execution of the tasks is pretty much straight forward and as one would expect.

---

<div class="post-metadata">

**Author:** ![KhalimWu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KhalimWu](https://forums.unrealengine.com/u/KhalimWu)\
**Post date:** [May 24, 2016, 10:48pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/13 "2016-05-24T22:48:02Z")

</div>

with Wait for sub Tree you mean Finish Mode to “Delayed”?

---

<div class="post-metadata">

**Author:** ![E1andri1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@E1andri1](https://forums.unrealengine.com/u/E1andri1)\
**Post date:** [May 24, 2016, 10:56pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/14 "2016-05-24T22:56:25Z")

</div>

yes (strange, you have to write at least 10 chars to answer)

---

<div class="post-metadata">

**Author:** ![ddbrown30](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ddbrown30](https://forums.unrealengine.com/u/ddbrown30)\
**Post date:** [September 30, 2016, 5:25pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/15 "2016-09-30T17:25:50Z")

</div>

The problem with this solution is that it has the opposite problem; once you finish the main task, it will never try to execute it again.

---

<div class="post-metadata">

**Author:** ![szundi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@szundi](https://forums.unrealengine.com/u/szundi)\
**Post date:** [December 29, 2016, 11:41am UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/16 "2016-12-29T11:41:57Z")

</div>

Sir, thank you Sir! 🙂

---

<div class="post-metadata">

**Author:** ![IRJayJay](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IRJayJay](https://forums.unrealengine.com/u/IRJayJay)\
**Post date:** [January 25, 2024, 2:52pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/17 "2024-01-25T14:52:29Z")

</div>

For anyone new getting till here and still finding it difficult to understand. Simple Parallel is really a misnomer. Probably the biggest UE documentation flop.

Anyway:  
It seems the main task is expected to be a long running task that’ll probably only Finish Execution after a while.

Finish Mode is set to immediate and immediate completing main task:  
If it finishes execution immediately it’ll repeat over and over and the background won’t really trigger because it’ll get cancelled over and over.

Finish Mode set to delayed and immediately completing main task:  
Main task finishes immediately and then the background task runs - which will appear as only the background task running.

Furthermore, I believe that adding e.g. a cooldown decorator on the node will cause both to stop running when the cooldown is activated. So I built a delay into my task directly, that’ll only Finish Execution after the delay.

I hope that makes sense.

---

<div class="post-metadata">

**Author:** ![Stratego](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/stratego/32/564611_2.png) [@Stratego](https://forums.unrealengine.com/u/Stratego)\
**Post date:** [March 25, 2024, 11:25pm UTC](https://forums.unrealengine.com/t/parallel-execution-in-behavior-tree/340740/18 "2024-03-25T23:25:29Z")

</div>

All these years later and this post is still good. This is what my problem was. My AI were stuttering and once I removed the Finish Execute all 300 AI runs and attacks smoothly now.

Thank you!
