From 4a50111f9b8dab5eb1f450b6689b6adef6ff2640 Mon Sep 17 00:00:00 2001 From: Menotdan <32620310+Menotdan@users.noreply.github.com> Date: Fri, 8 Dec 2023 01:46:55 -0500 Subject: [PATCH 1/2] Add infinite loop to behavior tree loop decorator. --- Source/Engine/AI/BehaviorTreeNodes.cpp | 6 ++++-- Source/Engine/AI/BehaviorTreeNodes.h | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) 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..170d0f59e 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)") 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)") BehaviorKnowledgeSelector LoopCountSelector; public: From 629ebacd646c33a9bf81a5c471aaa7724322d7eb Mon Sep 17 00:00:00 2001 From: Menotdan <32620310+Menotdan@users.noreply.github.com> Date: Fri, 8 Dec 2023 02:01:13 -0500 Subject: [PATCH 2/2] Hide loop count options if "Infinite Loop" is checked. --- Source/Engine/AI/BehaviorTreeNodes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Engine/AI/BehaviorTreeNodes.h b/Source/Engine/AI/BehaviorTreeNodes.h index 170d0f59e..b92f0f0d9 100644 --- a/Source/Engine/AI/BehaviorTreeNodes.h +++ b/Source/Engine/AI/BehaviorTreeNodes.h @@ -310,11 +310,11 @@ API_CLASS(Sealed) class FLAXENGINE_API BehaviorTreeLoopDecorator : public Behavi 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)") + 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. Unused if InfiniteLoop is used. - API_FIELD(Attributes="EditorOrder(30)") + API_FIELD(Attributes="EditorOrder(30), VisibleIf(nameof(InfiniteLoop), true)") BehaviorKnowledgeSelector LoopCountSelector; public: