Add ability to loop root node in behavior trees.

This commit is contained in:
Chandler Cox
2025-09-02 20:33:41 -05:00
parent eff5f84185
commit f588d6da51
2 changed files with 17 additions and 1 deletions

View File

@@ -106,7 +106,19 @@ void Behavior::UpdateAsync()
const BehaviorUpdateResult result = tree->Graph.Root->InvokeUpdate(context);
if (result != BehaviorUpdateResult::Running)
_result = result;
if (_result != BehaviorUpdateResult::Running)
if (_result != BehaviorUpdateResult::Running && tree->Graph.Root->Loop)
{
// Ensure to have tree loaded on play
CHECK(Tree && !Tree->WaitForLoaded());
BehaviorTree* tree = Tree.Get();
CHECK(tree->Graph.Root);
// Setup state
_result = BehaviorUpdateResult::Running;
_accumulatedTime = 0.0f;
_totalTime = 0;
}
else if (_result != BehaviorUpdateResult::Running)
{
Finished();
}

View File

@@ -96,6 +96,10 @@ API_CLASS(Sealed) class FLAXENGINE_API BehaviorTreeRootNode : public BehaviorTre
// The target amount of the behavior logic updates per second.
API_FIELD(Attributes="EditorOrder(100)")
float UpdateFPS = 10.0f;
// Whether to loop the root node.
API_FIELD(Attributes="EditorOrder(200)")
bool Loop = true;
};
/// <summary>