Skip to content

Commit 6f8610d

Browse files
committed
Fix missing ending of sub-trees when composites and root nodes are exited
1 parent 2781317 commit 6f8610d

File tree

5 files changed

+29
-6
lines changed

5 files changed

+29
-6
lines changed

Assets/com.fluid.behavior-tree/Runtime/TaskParents/Composites/CompositeBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace CleverCrow.Fluid.BTs.TaskParents.Composites {
1+
namespace CleverCrow.Fluid.BTs.TaskParents.Composites {
22
public abstract class CompositeBase : TaskParentBase {
33
public int ChildIndex { get; protected set; }
44

@@ -13,5 +13,9 @@ public override void Reset () {
1313

1414
base.Reset();
1515
}
16+
17+
protected void NotifyChildEnd(int childEnding) {
18+
Children[childEnding].End();
19+
}
1620
}
1721
}

Assets/com.fluid.behavior-tree/Runtime/TaskParents/Composites/Selector.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CleverCrow.Fluid.BTs.Tasks;
1+
using CleverCrow.Fluid.BTs.Tasks;
22

33
namespace CleverCrow.Fluid.BTs.TaskParents.Composites {
44
public class Selector : CompositeBase {
@@ -10,9 +10,13 @@ protected override TaskStatus OnUpdate () {
1010

1111
switch (child.Update()) {
1212
case TaskStatus.Success:
13+
NotifyChildEnd(ChildIndex);
1314
return TaskStatus.Success;
1415
case TaskStatus.Continue:
1516
return TaskStatus.Continue;
17+
case TaskStatus.Failure:
18+
NotifyChildEnd(ChildIndex);
19+
break;
1620
}
1721

1822
ChildIndex++;

Assets/com.fluid.behavior-tree/Runtime/TaskParents/Composites/SelectorRandom.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ protected override TaskStatus OnUpdate () {
2121

2222
switch (child.Update()) {
2323
case TaskStatus.Success:
24+
NotifyChildEnd(ChildIndex);
2425
return TaskStatus.Success;
2526
case TaskStatus.Continue:
2627
return TaskStatus.Continue;
28+
case TaskStatus.Failure:
29+
NotifyChildEnd(ChildIndex);
30+
break;
2731
}
2832

2933
ChildIndex++;

Assets/com.fluid.behavior-tree/Runtime/TaskParents/Composites/Sequence.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CleverCrow.Fluid.BTs.Tasks;
1+
using CleverCrow.Fluid.BTs.Tasks;
22

33
namespace CleverCrow.Fluid.BTs.TaskParents.Composites {
44
public class Sequence : CompositeBase {
@@ -9,8 +9,17 @@ protected override TaskStatus OnUpdate () {
99
var child = Children[ChildIndex];
1010

1111
var status = child.Update();
12-
if (status != TaskStatus.Success) {
13-
return status;
12+
switch (status) {
13+
case TaskStatus.Success:
14+
NotifyChildEnd(ChildIndex);
15+
break;
16+
case TaskStatus.Failure:
17+
NotifyChildEnd(ChildIndex);
18+
return status;
19+
case TaskStatus.Continue:
20+
return status;
21+
default:
22+
break;
1423
}
1524

1625
ChildIndex++;

Assets/com.fluid.behavior-tree/Runtime/TaskParents/TaskRoot.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CleverCrow.Fluid.BTs.Tasks;
1+
using CleverCrow.Fluid.BTs.Tasks;
22

33
namespace CleverCrow.Fluid.BTs.TaskParents {
44
public class TaskRoot : TaskParentBase {
@@ -16,6 +16,8 @@ protected override TaskStatus OnUpdate () {
1616
}
1717

1818
public override void End () {
19+
var child = Children[0];
20+
child.End();
1921
}
2022
}
2123
}

0 commit comments

Comments
 (0)