I found an unexpected behaviour when ConditionTask and BT. BT never trigger OnEnable/OnDisable for ConditionTask.
And For specific condition, like checking time, we can’t rely on conditionTask for Decorator.
See the linked screenshot to see the problem, with, for example, Timeout.
Indeed, the OnEnable and OnDisable methods are not used in Behaviour Trees but rather only in StateMachines, because there is not a very specific timing where a condition task is considered Enabled or Disabled in the context of a BT. With that said, other people have suggested that OnEnable is called once when the BT starts, and OnDisable be called once when the BT Stops, and this is something I am actually going to add. This however does not really solve the issue with Timeout, but I believe that Timeout could be implemented differently to avoid the requirement of OnEnable and OnDisable (I will need to think about how though).
Once again the issue here, is determining when OnEnable and OnDisable actually take place in the context of BTs for condition tasks. For FSMs it’s easy to determine the timing, but not as such in BT. If you have any suggestions at all in this matter, by all means, please do let me know!
I think it’s logic to call OnEnable in this case :
-Condition was not checked last graph update and now we check it.
For OnDisable : Condition was checked last graph update but not anymore. It happen if the current running Leaf change in various way : a Decorator not anymore running, a conditionTask not anymore running etc.
It’s very hard to implement timeout without this because when BehaviourTree pause for example I had trouble to fix this.
So, I’ve made the changes so that OnEnable and OnDisable are called in Behaviour Tree nodes.
For your information, OnEnable is called when the BT node was Resting and is now active.
OnDisable is called when the BT node is reset back to Resting.
This handles correctly the Timeout example, as well as other cases other people have pointed out.
It will be part of the next update. 🙂
Noted 🙂
I was about to send the new version tomorrow. I will see if I can squeeze that in. It is not as straightforward as it may seem. OnPause and OnResume for ActionTasks, are part of their own execution and for example OnPause in ActionTask, is called only if it is currently Running and the graph pauses. Since ConditionTasks do not have a “Running” state, OnPause and OnResume for them respectively, will need to be called whenever the graph pauses and resumes regardless of whether or not the ConditionTask was currently being evaluated (there is no “state” tracking that).
As such, I was planning to add callbacks in Tasks (for both Action and Condition) related to Graph state changes (OnGraphStarted, OnGraphStopped, OnGraphPaused and OnGraphResumed). These however are differnt (and called in different times) from the existing ActionTask OnPause and OnResume.
I hope this makes sense :). In any case, I will try to add these in the tomorrow version, or otherwise in the one right after that!
Hello,
I have attached for you here the modified version of ActionTask that has the OnResume virtual method implemented.
For ConditionTasks it is not really possible as explained in my previous post unfortunately, unless you mean a GraphPaused and GraphResume callback (which is something that I will add but need more changes all around).