NodeCanvas Forums › Support › Dynamic node execution order › Reply To: Dynamic node execution order
Hello again,
Thanks for the extra details.
It is actually neither intended, nor a bug, but rather a limitation on execution order when using dynamic nodes. Please allow me to explain what is going on:
When using a Dynamic Node (in this case the Dynamic Selector), the selector will keep reevaluating/executing all the leftmost child nodes of the currently Running child node. As soon as another child node on the left return Success (in case of Selector), the currently Running node will be interrupted (stopped) and the flow will continue down the new flow branch.
What this means, is that for a Success Status to be returned from a leftmost child node in the first place, that child node needs to be executed first (to determine Status) and only then the currently Running child node be interrupted.
As a result, what naturally happens is that OnExecute is called first (which is responsible for returning a Status.Success in the first place back to the Dynamic Selector), and only then the OnStop is called in the currently Running child node due to the interruption taking place from that Dynamic Selector.
I really hope this explanation made sense as to clarify why and what is going on.
OnExecute callbacks will of course always execute in the correct order, but OnStop callbacks and depending on the situation (specifically moving from a right-most node to a left-most node due to a parent Dynamic node), are not called in order as explained above. As such, when using Dynamic nodes (and even in general), it is best to not depend on the order of execution for the OnStop callbacks to “prepare” the next tasks, from a previous task. Ideally, each task should be as independent as possible and this is why the OnStop callback should best be used only to “reset” things relevant to the task iteself.
Using OnExecute though, once again, is completely safe execution-order wise.
Please let me know if that helps at all.
If you let me know what you are after in a bit more detail, I am sure we could find another solution to what you want to achieve, without relying on the OnStop callback.
Thank you!
Join us on Discord: https://discord.gg/97q2Rjh