OnExit (OnAbort) branch or sequence Logic

KO_Games

Member
I love working with behavior trees over state machines for the most part, but one thing that I haven't quite figured out how to solve in a nice way is something like an OnExit to be triggered when a sequence gets aborted.

For example, let's say you have a simple tree with a selector that is repeated forever. It then has 3 child sequences to pick from. The first two children have the abort type set to lower priority. If the first two child sequences cannot be entered in due to some logic it will default to running the rightmost child sequence. If at some point during gameplay, the game state changes so that the left-most first child's condition is now true, the right-most child gets aborted and we move to the left-most first child since it has the highest priority.

The question I then have often is what if when the right-most child gets aborted I want to make sure some event is fired or a bool is set? I often find myself having to paste in the same event or set bool task in each of the higher-priority children because I have not found a way to fire the event/set some bool on exit (on abort) from the lower-priority child that was just aborted.

Or maybe there is another better way to handle these use cases?

I did see that there is an OnConditionalAbort function on the Sequence task script. I suppose I could create a custom sequence that inherits from this one that has the option to set some bool or fire some event, but this seems like it could be a little tedious to do for every use case. For example, what if you wanted to set multiple bools or fire multiple events? And then you are also complicating the code in the new custom sequence by adding in the logic for a fire event and a set bool into it as well.
 
What might be nice is if there was a way to execute some task or a series of tasks by using an OnConditionalAbort with the sequence.
 
There isn't anything built in for this use case and as you mentioned overriding one of the methods and firing an event is the best method to handle this generically. Having exit tasks is something that I plan on exploring for version 2.
 
@Justin I tried to copy the code from the sequence into a new script so I could add some custom logic to the sequence without editing the original sequence task script. However, I noticed that OnConditionalAbort never gets called in this duplicated script when connected to the tree. If I add a log into the original sequence task script though it does seem to get called.
Do you know why the OnConditionalAbort only seems to get called in the original sequence task script and not duplicated or inherited scripts?
 
No - there's not anything special about the built in tasks. OnConditionalAbort it called on any parent task that is aborted.
 
Top