Is there a way to make a Task version of OnDisable

jfcarter

New member
Task have OnAwake which is kind of like an OnEnable since its only called once everytime the tree is enabled (and the task has been hit). Is there a way to make a OnBehaviorDisable when the behavior tree is turned off? Right now the closest is OnEnd but this is only called when the task is exited instead of when the behavior tree is turned off. What I want to do is subscribe to events on awake and unsubscribe OnBehaviorDisable if possible. Right now I get around it by unsubscribing first (see below). I do this on some awakes because I need the callbacks to run even when the task isnt playing. My thought process is to edit the behaviortree task and listen for its ondisable and then add some method to Task.cs and BehaviorManager.cs that would handle it. Not super sure how to get it done if at all possible.

//Note behaviorHandler is a custom shared variable
public override void OnAwake()
{
behaviorHandler.Value.AiEvents.attentionCaught -= AttentionCaught;
behaviorHandler.Value.AiEvents.attentionLost -= AttentionLost;

behaviorHandler.Value.AiEvents.attentionCaught += AttentionCaught;
behaviorHandler.Value.AiEvents.attentionLost += AttentionLost;
}
 
There is an OnBehaviorComplete callback that you can subscribe to for that purpose.
 
Back
Top