Merge pull request #44794 from RandomShaper/fix_inst_resource
Fix instantiation of resource as property value
This commit is contained in:
commit
4486aa8014
1 changed files with 7 additions and 5 deletions
|
@ -2546,10 +2546,12 @@ void EditorPropertyResource::_menu_option(int p_which) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *obj = nullptr;
|
Object *obj = nullptr;
|
||||||
|
RES res_temp;
|
||||||
|
|
||||||
if (ScriptServer::is_global_class(intype)) {
|
if (ScriptServer::is_global_class(intype)) {
|
||||||
obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype));
|
obj = ClassDB::instance(ScriptServer::get_global_class_native_base(intype));
|
||||||
if (obj) {
|
if (obj) {
|
||||||
|
res_temp = obj;
|
||||||
Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype));
|
Ref<Script> script = ResourceLoader::load(ScriptServer::get_global_class_path(intype));
|
||||||
if (script.is_valid()) {
|
if (script.is_valid()) {
|
||||||
obj->set_script(Variant(script));
|
obj->set_script(Variant(script));
|
||||||
|
@ -2557,21 +2559,21 @@ void EditorPropertyResource::_menu_option(int p_which) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
obj = ClassDB::instance(intype);
|
obj = ClassDB::instance(intype);
|
||||||
|
res_temp = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!obj) {
|
if (!obj) {
|
||||||
obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
|
obj = EditorNode::get_editor_data().instance_custom_type(intype, "Resource");
|
||||||
|
res_temp = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
ERR_BREAK(!obj);
|
ERR_BREAK(!res_temp.is_valid());
|
||||||
Resource *resp = Object::cast_to<Resource>(obj);
|
|
||||||
ERR_BREAK(!resp);
|
|
||||||
if (get_edited_object() && base_type != String() && base_type == "Script") {
|
if (get_edited_object() && base_type != String() && base_type == "Script") {
|
||||||
//make visual script the right type
|
//make visual script the right type
|
||||||
resp->call("set_instance_base_type", get_edited_object()->get_class());
|
res_temp->call("set_instance_base_type", get_edited_object()->get_class());
|
||||||
}
|
}
|
||||||
|
|
||||||
res = Ref<Resource>(resp);
|
res = res_temp;
|
||||||
emit_changed(get_edited_property(), res);
|
emit_changed(get_edited_property(), res);
|
||||||
update_property();
|
update_property();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue