Fix crash when looping BT with Force Success node
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user