How to implement action to react conditional abort correctly?

Archer

New member
Hi, I'm a little confused about conditional abort. Below image is the example on document. Let's say at first time, "Can See Object" evaluates to Success, then Action(assume it to attack) begins to execute, in OnStart method, I play a attack animation, and start a timer to hurt the target at certain time periodically. Then at some time, "Can See Object" evaluate to Failure, the Action will be aborted immediately, OnEnd is called, I stop the animation and the timer. But if "Can Hear Object" also evaluate to Success, the Action will enter and execute again, and will repeat the OnStart, the animation and timer will be reset to start. If animation and timer is on half way when previous abort occur, this will cause incorrect behavior. Logically, Action is always valid, but with conditional abort, it experiences in-out-in stages. More generally, with conditional abort, Action's OnStart is not guarantee that the action is first execute, and OnEnd is not guarantee that action is really to the end. One solution is to use states to know if the action is enter or leave attack state. But if we rely on states, why not just use FSM?

Screen Shot 2021-03-26 at 12.36.54 PM.png

I think I have some misunderstanding on how to use behavior tree correctly, so could you please show me how to use action with conditional abort, for example to solve this problem? Thanks in advance!
 
The OnStart/OnEnd methods will only be called when the task has started or ended. In your case the Action task can start when either Can See Object or Can Hear Object returns success, and it will stop when both of those return failure.
 
I means (“can see object” = true and “can hear object” = false) and (“can see object” = false and “can hear object” = true) both make Action available to execute, but when first condition switch to second one, will make Action to be re-evaluated, OnEnd-> OnStart, is this intrinsic or can be avoided?
 
Ah, I see. That's the way conditional aborts work so with that you have two options:

1. Create a new task which combines Can See Object/Can Hear Object into a single conditional task.
2. Don't use conditional aborts and instead use the Interrupt/Perform Interruption tasks. This will give you more control over when a branch is aborted.
 
Top