Fix crash when looping BT with Force Success node

This commit is contained in:
2026-09-24 23:38:50 +02:00
parent 0d4ea64caa
commit 0c63c91a7d
2 changed files with 18 additions and 7 deletions
+16 -7
View File
@@ -107,16 +107,25 @@ void Behavior::UpdateAsync()
context.DeltaTime = updateDeltaTime;
context.Time = _totalTime;
const BehaviorUpdateResult result = tree->Graph.Root->InvokeUpdate(context);
if (result != BehaviorUpdateResult::Running)
if (_result == BehaviorUpdateResult::Running && result != BehaviorUpdateResult::Running)
{
// Update result
_result = result;
if (_result != BehaviorUpdateResult::Running && tree->Graph.Root->Loop)
{
// Reset State
_result = BehaviorUpdateResult::Running;
if (_result != BehaviorUpdateResult::Running && tree->Graph.Root->Loop)
{
// Reset State
_result = BehaviorUpdateResult::Running;
}
else if (_result != BehaviorUpdateResult::Running)
{
// End
Finished();
}
}
else if (_result != BehaviorUpdateResult::Running)
else if (_result != BehaviorUpdateResult::Running && tree->Graph.Root->Loop)
{
Finished();
// Restart on end (eg. after Force Success node during Update)
StartLogic();
}
}
+2
View File
@@ -112,6 +112,8 @@ BehaviorUpdateResult BehaviorTreeNode::InvokeUpdate(const BehaviorUpdateContext&
result = Update(context);
if ((int32)result < 0 || (int32)result > (int32)BehaviorUpdateResult::Failed)
result = BehaviorUpdateResult::Failed; // Invalid value is a failure
if (context.Behavior->GetResult() != BehaviorUpdateResult::Running)
return result; // Behavior is already finished, no need to continue
// Post-process result from decorators
for (BehaviorTreeDecorator* decorator : _decorators)