fix: frame only ends when viable leaf is found

This commit is contained in:
Sara Gerretsen 2026-03-15 10:44:08 +01:00
parent 16ba0418f9
commit d2b91de4d6
3 changed files with 8 additions and 8 deletions

View file

@ -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);
}

View file

@ -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);
};

View file

@ -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<BehaviourComposite>(this->current) || this->current->get_status() == BehaviourNode::Fail;