Better error handling when resolving _generate_name

This commit is contained in:
Serhii Snitsaruk 2024-02-10 15:05:50 +01:00
parent 899335d1fe
commit 654eda1c65
2 changed files with 16 additions and 5 deletions

View File

@ -128,9 +128,17 @@ String BTTask::get_task_name() {
}
return _generate_name();
#elif LIMBOAI_GDEXTENSION
String s;
VCALL_OR_NATIVE_V(_generate_name, String, s);
return s;
Ref<Script> task_script = get_script();
if (task_script.is_valid() && task_script->is_tool()) {
Variant call_result;
VCALL_OR_NATIVE_V(_generate_name, Variant, call_result);
ERR_FAIL_COND_V(call_result.get_type() == Variant::NIL, _generate_name());
String task_name = call_result;
ERR_FAIL_COND_V(task_name.is_empty(), _generate_name());
return task_name;
} else {
return _generate_name();
}
#endif
}
return data.custom_name;
@ -343,7 +351,10 @@ PackedStringArray BTTask::get_configuration_warnings() {
PackedStringArray ret;
PackedStringArray warnings;
Ref<Script> task_script = get_script();
if (task_script.is_valid() && task_script->is_tool()) {
VCALL_V(_get_configuration_warnings, warnings); // Get script warnings.
}
ret.append_array(warnings);
ret.append_array(_get_configuration_warnings());

View File

@ -124,7 +124,7 @@ Ref<BTTask> LimboAIEditor::_create_task_by_class_or_path(const String &p_class_o
if (p_class_or_path.begins_with("res:")) {
Ref<Script> s = RESOURCE_LOAD(p_class_or_path, "Script");
ERR_FAIL_COND_V_MSG(s.is_null() || !s->can_instantiate(), nullptr, vformat("LimboAI: Failed to instantiate task. Bad script: %s", p_class_or_path));
ERR_FAIL_COND_V_MSG(s.is_null(), nullptr, vformat("LimboAI: Failed to instantiate task. Bad script: %s", p_class_or_path));
Variant inst = ClassDB::instantiate(s->get_instance_base_type());
ERR_FAIL_COND_V_MSG(inst == Variant(), nullptr, vformat("LimboAI: Failed to instantiate base type \"%s\".", s->get_instance_base_type()));