Behaviour Trees in NodeCanvas are designed with the ability to react to immediate changes which is a requirement for most modern fast-paced games.
Many Behaviour Tree nodes have a special option named “Dynamic”. With this option enabled the node will react immediately to child node status changes. Let’s take an example for convenience:
Suppose we have this simple behaviour tree where if “myBoolean” variable is true, then we will wait 1000 seconds (exaggerated on purpose), which resembles an action that can possibly take that much time. If while that action is Running the condition no longer holds true (myBoolean is false), then nothing will happen. The condition will not be evaluated until the next tree traversal.
To make this Sequencer Reactive, all we have to do is to enable its Dynamic option. As such, even while the action Wait 1000 seconds is running, if the condition becomes false, the action will be interrupted and the Sequencer will be re-evaluated, which will result in it returning Failure as it should.
The dynamic option works only in the scope of the node being Dynamic. So if you had the following behaviour tree, if while “Action 2” is running “myBoolean” becomes true, the Selector won’t really care about this change and “Action 2” will continue to run.
Making the Selector Dynamic as well will solve this correctly. So in the following tree, if “Action 2” is running and “myBoolean” becomes true, “Action 2” will be interrupted and the Sequencer will take over. As a consequence, since the condition is true, “Action 1” will execute. If the condition later becomes false, the Sequencer being Dynamic, will interrupt “Action 1” and return Failure. Then the Selector will execute “Action 2”.
If you are making a game that needs reactive evaluation like for example an action or a realtime strategy game, then the Dynamic option is certain to help you.
The Dynamic option can been found in the following Behaviour Tree Nodes: