Conditional Abort triggers task twice in a row

Necronomison

New member
Hi there!

I know I posted a similar question here:
https://www.opsive.com/forum/index....gain-after-conditional-abort.8574/#post-42333

In that case it turned out to be the unexpected behavior of mixing parallel tasks with conditional aborts.

I'm seeing a similar issue with this graph below, but this time there's no parallel task. The graph looks like this:
1681098668068.png

Observed Behavior:
1. The conditional check circled (1) re-evaluates to false while the task to the right of it is running (as expected since their parent Sequence task is set to 'Self' conditional abort)
2. The result of that sequence branch failing then fails the parent sequence task above (circle 2), and so the Selector task above moves over to the right branch.
3. Conditional task circled (3) evaluates to true (as expected, its the same boolean check as circle 1)
4. Custom task (circle 4) then runs twice immediately in a row (not expected). Putting a breakpoint shows the following calls in order: OnStart(), OnEnd(), OnStart(), OnEnd().

What's curious is The first pair of OnStart and OnEnd calls happen instantaneously, where the OnEnd() callstack shows that it was invoked because of a conditional import.

Here are the four callstacks:

1).
1681099602132.png

2).
1681099772848.png

3).
1681099796257.png

4).
1681099820414.png

Basically, I don't understand where the first pair of OnStart() OnEnd() calls are coming from. More curious is that the second OnEnd() seems to be invoked because of a conditional abort (see the red underling in the second callstack image).

Any help would be greatly appreciated!
 
Have you tried enabling logging on the behavior tree? This should give more details as to what caused the task to run twice.
 
Very interesting. Here are the two logs for when its pushing and popping task (circle 4) for the first pair of OnStart() OnEnd()

Code:
76.44537: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task While Staggered (Duffins.Staggered, index 25) at stack index 0

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Conditional abort with task Sequence (BehaviorDesigner.Runtime.Tasks.Sequence, index 13) because of conditional task Is Ability Cooling Down (BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables.CompareSharedBool, index 14) with status Failure

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Pop task While Staggered (Duffins.Staggered, index 25) at stack index 0 with status Failure

hmmm....
 
And then further down it logs:
Code:
76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task Is Ability Cooling Down (BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables.CompareSharedBool, index 14) at stack index 0
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Pop task Is Ability Cooling Down (BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables.CompareSharedBool, index 14) at stack index 0 with status Failure
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Pop task Sequence (BehaviorDesigner.Runtime.Tasks.Sequence, index 13) at stack index 0 with status Failure
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task Selector (BehaviorDesigner.Runtime.Tasks.Selector, index 22) at stack index 0
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task Sequence (BehaviorDesigner.Runtime.Tasks.Sequence, index 23) at stack index 0
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task Staggered (BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables.CompareSharedBool, index 24) at stack index 0
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Pop task Staggered (BehaviorDesigner.Runtime.Tasks.Unity.SharedVariables.CompareSharedBool, index 24) at stack index 0 with status Success
UnityEngine.MonoBehaviour:print (object)

76.45721: Skelly_Gladiator(Clone) - Skelly_Gladiator: Push task While Staggered (Duffins.Staggered, index 25) at stack index 0
UnityEngine.MonoBehaviour:print (object)

So I think what might be happening is that both the sequences fail (as expected/noted in my original post), it goes to the sequence to the right, starts to run task circled 4, and then the left most conditional (re)evaluates to false (circled in the image below) which briefly causes the tree to evaluate the left branch again because of conditional aborts. That sequence fails AGAIN, and then the right branch runs for a second time.

Sigh, looks like I really need to re-evaluate my design patterns and how much I rely on conditional aborts.


1681109086255.png
 
Posting for posterity:

I solved my issue by replacing the conditional abort in this one case for an interrupt. This way its incredibly clear when (and ONLY when) the branch on the left can run.

1681114451966.png
 
Top