diff --git a/Source/Engine/AI/BehaviorTreeNodes.cpp b/Source/Engine/AI/BehaviorTreeNodes.cpp index fb49a007e..42b12d911 100644 --- a/Source/Engine/AI/BehaviorTreeNodes.cpp +++ b/Source/Engine/AI/BehaviorTreeNodes.cpp @@ -624,8 +624,10 @@ void BehaviorTreeLoopDecorator::PostUpdate(const BehaviorUpdateContext& context, if (result == BehaviorUpdateResult::Success) { auto state = GetState(context.Memory); - state->Loops--; - if (state->Loops > 0) + if (!InfiniteLoop) + state->Loops--; + + if (state->Loops > 0 || InfiniteLoop) { // Keep running in a loop but reset node's state (preserve self state) result = BehaviorUpdateResult::Running; diff --git a/Source/Engine/AI/BehaviorTreeNodes.h b/Source/Engine/AI/BehaviorTreeNodes.h index d72bdee04..b92f0f0d9 100644 --- a/Source/Engine/AI/BehaviorTreeNodes.h +++ b/Source/Engine/AI/BehaviorTreeNodes.h @@ -305,12 +305,16 @@ API_CLASS(Sealed) class FLAXENGINE_API BehaviorTreeLoopDecorator : public Behavi DECLARE_SCRIPTING_TYPE_WITH_CONSTRUCTOR_IMPL(BehaviorTreeLoopDecorator, BehaviorTreeDecorator); API_AUTO_SERIALIZATION(); - // Amount of times to execute the node. Unused if LoopCountSelector is used. - API_FIELD(Attributes="EditorOrder(10), Limit(0)") + // Is the loop infinite (until failed)? + API_FIELD(Attributes = "EditorOrder(10)") + bool InfiniteLoop = false; + + // Amount of times to execute the node. Unused if LoopCountSelector is used or if InfiniteLoop is used. + API_FIELD(Attributes="EditorOrder(20), Limit(0), VisibleIf(nameof(InfiniteLoop), true)") int32 LoopCount = 3; - // Amount of times to execute the node from behavior's knowledge (blackboard, goal or sensor). If set, overrides LoopCount. - API_FIELD(Attributes="EditorOrder(20)") + // Amount of times to execute the node from behavior's knowledge (blackboard, goal or sensor). If set, overrides LoopCount. Unused if InfiniteLoop is used. + API_FIELD(Attributes="EditorOrder(30), VisibleIf(nameof(InfiniteLoop), true)") BehaviorKnowledgeSelector LoopCountSelector; public: