Merge branch 'Menotdan-bt_infinite_loop'

This commit is contained in:
Wojtek Figat
2023-12-08 10:34:38 +01:00
2 changed files with 12 additions and 6 deletions

View File

@@ -624,8 +624,10 @@ void BehaviorTreeLoopDecorator::PostUpdate(const BehaviorUpdateContext& context,
if (result == BehaviorUpdateResult::Success)
{
auto state = GetState<State>(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;

View File

@@ -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<int32> LoopCountSelector;
public: