Fix crash while initializing blackboard in the BTPlayer node

This commit is contained in:
Serhii Snitsaruk 2024-01-23 16:22:10 +01:00
parent dc40109ade
commit f84127657b
2 changed files with 10 additions and 5 deletions

View File

@ -70,11 +70,12 @@ void Blackboard::add_var(const String &p_name, const BBVariable &p_var) {
void Blackboard::prefetch_nodepath_vars(Node *p_node) {
ERR_FAIL_COND(p_node == nullptr);
for (KeyValue<String, BBVariable> &kv : data) {
if (kv.value.get_value().get_type() == Variant::NODE_PATH) {
Node *fetched_node = p_node->get_node_or_null(kv.value.get_value());
for (const KeyValue<String, BBVariable> &kv : data) {
BBVariable var = kv.value;
if (var.get_value().get_type() == Variant::NODE_PATH) {
Node *fetched_node = p_node->get_node_or_null(var.get_value());
if (fetched_node != nullptr) {
kv.value.set_value(fetched_node);
var.set_value(fetched_node);
}
}
}

View File

@ -179,8 +179,11 @@ void BTPlayer::_notification(int p_notification) {
} break;
case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint()) {
if (blackboard.is_null()) {
blackboard = Ref<Blackboard>(memnew(Blackboard));
}
if (blackboard_source.is_valid()) {
blackboard = blackboard_source->create_blackboard();
blackboard_source->populate_blackboard(blackboard, false);
}
if (behavior_tree.is_valid()) {
_load_tree();
@ -247,6 +250,7 @@ void BTPlayer::_bind_methods() {
}
BTPlayer::BTPlayer() {
blackboard = Ref<Blackboard>(memnew(Blackboard));
}
BTPlayer::~BTPlayer() {