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.
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.