From d2b91de4d645ed87d544765bc8855536d7538f60 Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 15 Mar 2026 10:44:08 +0100 Subject: [PATCH] fix: frame only ends when viable leaf is found --- behaviour_action.cpp | 6 ++++-- behaviour_action.h | 4 ++-- behaviour_tree.cpp | 6 ++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/behaviour_action.cpp b/behaviour_action.cpp index 0351a74c..34b60722 100644 --- a/behaviour_action.cpp +++ b/behaviour_action.cpp @@ -9,11 +9,13 @@ void BehaviourAction::_bind_methods() { } void BehaviourAction::enter() { - GDVIRTUAL_CALL(_enter); + Status out_status{ get_status() }; + GDVIRTUAL_CALL(_enter, out_status); + set_status(out_status); } void BehaviourAction::execute() { - Status out_status{ Fail }; + Status out_status{ get_status() }; GDVIRTUAL_CALL(_execute, out_status); set_status(out_status); } diff --git a/behaviour_action.h b/behaviour_action.h index 8f61a5d0..b9608a70 100644 --- a/behaviour_action.h +++ b/behaviour_action.h @@ -11,7 +11,7 @@ public: void execute() override; void exit() override; BehaviourNode *get_next() override; - GDVIRTUAL0R_REQUIRED(Status, _execute); - GDVIRTUAL0(_enter); + GDVIRTUAL0R(Status, _execute); + GDVIRTUAL0R(Status, _enter); GDVIRTUAL0(_exit); }; diff --git a/behaviour_tree.cpp b/behaviour_tree.cpp index 78bd209f..2aed80a5 100644 --- a/behaviour_tree.cpp +++ b/behaviour_tree.cpp @@ -7,10 +7,9 @@ void BehaviourTree::_bind_methods() {} void BehaviourTree::process() { - this->current->execute(); - while (execute_next()) { + do { this->current->execute(); - } + } while (execute_next()); } void BehaviourTree::_notification(int what) { @@ -46,7 +45,6 @@ bool BehaviourTree::execute_next() { } if (this->current->get_parent() != next) { next->enter(); - next->execute(); } this->current = next; return cast_to(this->current) || this->current->get_status() == BehaviourNode::Fail;