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;