If you have a BD Action that starts a new behavior tree on the current object, you have to be careful about what you return from that Action.
Look at this snippet of source:
This happens in BehaviorManager#RunTask immediately after the Action's OnUpdate method is called. It doesn't check for the (admittedly unlikely) event that the behavior tree changed; so unless you return `TaskStatus.Running`, PopTask will be called on the new behavior tree, which causes weird behavior (like Conditional nodes getting skipped). The workaround here is to make sure to return TaskStatus.Running in the task that switches behavior trees.
I'm not sure what exactly the right answer here is; more documentation, or logging a warning if the tree changed but we didn't return TaskStatus.Running, or...just making it work.
For me, I'm going to look into whether I can actually use BD's `StartBehaviorTree` which might be a safer way to do what I'm doing rather than reassigning the behavior in my own code.
Look at this snippet of source:
C#:
if (status != TaskStatus.Running) {
// pop the task immediately if the task is instant. If the task is not instant then wait for the next update
if (task.IsInstant) {
PopTask(behaviorTree, taskIndex, stackIndex, ref status, true);
} else {
behaviorTree.nonInstantTaskStatus[stackIndex] = status;
}
}
This happens in BehaviorManager#RunTask immediately after the Action's OnUpdate method is called. It doesn't check for the (admittedly unlikely) event that the behavior tree changed; so unless you return `TaskStatus.Running`, PopTask will be called on the new behavior tree, which causes weird behavior (like Conditional nodes getting skipped). The workaround here is to make sure to return TaskStatus.Running in the task that switches behavior trees.
I'm not sure what exactly the right answer here is; more documentation, or logging a warning if the tree changed but we didn't return TaskStatus.Running, or...just making it work.
For me, I'm going to look into whether I can actually use BD's `StartBehaviorTree` which might be a safer way to do what I'm doing rather than reassigning the behavior in my own code.