fix: behaviourtree ends frame when root is hit
This commit is contained in:
parent
fef1e3f8bd
commit
427c0a7ec8
3 changed files with 10 additions and 5 deletions
|
|
@ -14,15 +14,17 @@ protected:
|
|||
void _notification(int what);
|
||||
|
||||
public:
|
||||
virtual void enter() {}
|
||||
virtual void execute() {}
|
||||
virtual void enter() {
|
||||
set_status(Fail);
|
||||
}
|
||||
virtual void exit() {}
|
||||
virtual BehaviourNode *get_next() { return this; }
|
||||
|
||||
private:
|
||||
class BehaviourTree *behaviour_tree{ nullptr };
|
||||
BehaviourNode *parent{ nullptr };
|
||||
Status status{};
|
||||
Status status{ Fail };
|
||||
bool leaf{ false };
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "behaviour_tree.h"
|
||||
#include "behaviour_nodes/behaviour_composite.h"
|
||||
#include "behaviour_nodes/behaviour_node.h"
|
||||
#include "behaviour_nodes/control_nodes.h"
|
||||
#include "core/config/engine.h"
|
||||
#include "core/variant/typed_array.h"
|
||||
|
||||
|
|
@ -21,11 +22,12 @@ void BehaviourTree::_notification(int what) {
|
|||
return;
|
||||
case NOTIFICATION_READY:
|
||||
for (Variant var : get_children()) {
|
||||
if ((this->current = cast_to<BehaviourNode>(var))) {
|
||||
if ((this->root = cast_to<BehaviourNode>(var))) {
|
||||
this->current = this->root;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ERR_FAIL_COND_EDMSG(this->current == nullptr, "No valid BehaviourNode in BehaviourTree");
|
||||
ERR_FAIL_COND_EDMSG(this->root == nullptr, "No valid BehaviourNode in BehaviourTree");
|
||||
set_process(true);
|
||||
return;
|
||||
case NOTIFICATION_PROCESS:
|
||||
|
|
@ -47,6 +49,6 @@ bool BehaviourTree::execute_next() {
|
|||
next->enter();
|
||||
}
|
||||
this->current = next;
|
||||
return cast_to<BehaviourComposite>(this->current) || this->current->get_status() == BehaviourNode::Fail;
|
||||
return this->current != this->root && (cast_to<BehaviourComposite>(this->current) || this->current->get_status() != BehaviourNode::Running);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,5 @@ public:
|
|||
|
||||
private:
|
||||
class BehaviourNode *current{ nullptr };
|
||||
class BehaviourNode *root{ nullptr };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue