NodeCanvas Forums › Support › Parallel node does not work correctly on first run › Reply To: Parallel node does not work correctly on first run
Hello again. There is a misunderstanding of how the Parallel node works unfortunately; In the example you posted above the Parallel node works as it should, but I will do my best to explain why.
– So, when the Parallel is set to “Repeat”, it will repeat its finished children/branches until the policy is met, or until all children have had a chance to finish at least once. (at which point it will return a status according to the policy set and in our case the tree reset since the Parallel here is the root node).
So what is happening here is:
1) The first time the tree runs, the right branch is finished as soon as the Wait 1 Second action completes. However the left branch is still not finished since there is a Wait Until node.
2) When “mySecondBoolean” is set to True and the Conditional node goes Running, the right branch remains finished and the left branch remains un-finished.
3) When “myBoolean” is set to True (therefore triggering the Wait Until node), the left branch finally becomes finished.
Since now both the left and the right branches have had a chance to complete/finish, the Parallel node returns and the tree resets.
4) We are now on a new tree cycle. Both branches are now un-finished. The left branch is un-finished because of the Wait Until node still waiting, but also the right branch is un-finished since the Wait 100000 seconds is running long.
5) When we set “myBoolean” to True now, the left branch is getting finished, however the right branch remains un-finished since the Wait 100000 seconds is still running. Therefore the Parallel does not return and the tree not reset since the condition “both children have had a chance to finish at least once” is NOT met.
Here is a gif (replication similar to your test tree) in which I have also added debug information on the connections of the Parallel node (which is probably a good idea to have anyway) which will hopefully better help understand the above:
I have also attached an mp4 video so it is easier to scroll through time.
ParallelRepeat
You can also easily add the debug info on the connections I have now added by adding this code in Parallel.cs node:
1 2 3 4 5 6 7 8 |
public override string GetConnectionInfo(int i) { if ( dynamic && status == Status.Running ) { return string.Format("Branch Finished: {0}", finishedConnections<em class="d4pbbc-italic"></em>.ToString()); } return null; } |
This will certainly also help you debug and understand what is happening in your other first tree that you posted.
I did my best to explain what is happening and why the Parallel node works as it should in the end, but please let me know if you need any further elaboration. Thanks.
Join us on Discord: https://discord.gg/97q2Rjh