|
39 | 39 | #include "editor/multi_node_edit.h" |
40 | 40 | #include "editor/plugins/editor_context_menu_plugin.h" |
41 | 41 | #include "editor/plugins/editor_plugin.h" |
| 42 | +#include "scene/property_utils.h" |
42 | 43 | #include "scene/resources/packed_scene.h" |
43 | 44 |
|
44 | 45 | void EditorSelectionHistory::cleanup_history() { |
@@ -536,15 +537,18 @@ Variant EditorData::instantiate_custom_type(const String &p_type, const String & |
536 | 537 | if (get_custom_types()[p_inherits][i].name == p_type) { |
537 | 538 | Ref<Script> script = get_custom_types()[p_inherits][i].script; |
538 | 539 |
|
539 | | - Variant ob = ClassDB::instantiate(p_inherits); |
540 | | - ERR_FAIL_COND_V(!ob, Variant()); |
| 540 | + // Store in a variant to initialize the refcount if needed. |
| 541 | + Variant v = ClassDB::instantiate(p_inherits); |
| 542 | + ERR_FAIL_COND_V(!v, Variant()); |
| 543 | + Object *ob = v; |
| 544 | + |
541 | 545 | Node *n = Object::cast_to<Node>(ob); |
542 | 546 | if (n) { |
543 | 547 | n->set_name(p_type); |
544 | 548 | } |
545 | | - n->set_meta(SceneStringName(_custom_type_script), script); |
546 | | - ((Object *)ob)->set_script(script); |
547 | | - return ob; |
| 549 | + PropertyUtils::assign_custom_type_script(ob, script); |
| 550 | + ob->set_script(script); |
| 551 | + return v; |
548 | 552 | } |
549 | 553 | } |
550 | 554 | } |
@@ -988,12 +992,13 @@ Variant EditorData::script_class_instance(const String &p_class) { |
988 | 992 | Ref<Script> script = script_class_load_script(p_class); |
989 | 993 | if (script.is_valid()) { |
990 | 994 | // Store in a variant to initialize the refcount if needed. |
991 | | - Variant obj = ClassDB::instantiate(script->get_instance_base_type()); |
992 | | - if (obj) { |
993 | | - Object::cast_to<Object>(obj)->set_meta(SceneStringName(_custom_type_script), script); |
994 | | - obj.operator Object *()->set_script(script); |
| 995 | + Variant v = ClassDB::instantiate(script->get_instance_base_type()); |
| 996 | + if (v) { |
| 997 | + Object *obj = v; |
| 998 | + PropertyUtils::assign_custom_type_script(obj, script); |
| 999 | + obj->set_script(script); |
995 | 1000 | } |
996 | | - return obj; |
| 1001 | + return v; |
997 | 1002 | } |
998 | 1003 | } |
999 | 1004 | return Variant(); |
|
0 commit comments