Parent Tasks
ParentTask is the base for Composites and Decorators. Override it when child count, traversal order, parallel execution, result decoration, or conditional-abort recovery differs from the included parent tasks.
Child capacity and execution
public override int MaxChildren() => 1;
public override bool CanRunParallelChildren() => false;
public override int CurrentChildIndex() => m_CurrentChild;
public override bool CanExecute() => m_CurrentChild < Children.Count;
MaxChildren normally returns 1 for a Decorator or int.MaxValue for a Composite. CanExecute and CurrentChildIndex tell the runtime which child is eligible next. Override CanRunParallelChildren only when the parent owns the completion rules for several active children.
Receive child results
public override void OnChildStarted(int childIndex) { }
public override void OnChildExecuted(int childIndex, TaskStatus childStatus) { }
public override TaskStatus Decorate(TaskStatus status) => status;
public override TaskStatus OverrideStatus(TaskStatus status) => status;
Use the indexed callbacks for parallel parents. A Decorator changes its single child’s result in Decorate. A Composite can replace the calculated result in OverrideStatus when its completion rule requires it.
Respond to conditional aborts
public override void OnConditionalAbort(int childIndex)
{
m_CurrentChild = childIndex;
}
Reset only the traversal state that should be reconsidered after the abort. Leaving stale child indexes is a common reason a custom Composite resumes at the wrong branch.
Before implementing a parent from scratch, compare the included Sequence, Selector, Parallel, Repeater, and Inverter tasks. Use Conditional Aborts to verify custom abort behavior and Debugging to inspect the active child.