feat: signal triggers when current behaviour node changes

This commit is contained in:
Sara Gerretsen 2026-03-20 19:41:50 +01:00
parent 427c0a7ec8
commit a9158c8e48

View file

@ -1,11 +1,14 @@
#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/object/class_db.h"
#include "core/object/object.h"
#include "core/variant/typed_array.h"
void BehaviourTree::_bind_methods() {}
void BehaviourTree::_bind_methods() {
ADD_SIGNAL(MethodInfo("current_behaviour_changed", PropertyInfo(Variant::OBJECT, "new_behaviour", PROPERTY_HINT_NODE_TYPE, "BehaviourNode")));
}
void BehaviourTree::process() {
do {
@ -47,6 +50,7 @@ bool BehaviourTree::execute_next() {
}
if (this->current->get_parent() != next) {
next->enter();
emit_signal("current_behaviour_changed", next);
}
this->current = next;
return this->current != this->root && (cast_to<BehaviourComposite>(this->current) || this->current->get_status() != BehaviourNode::Running);