From 06998a3927e1c36212ba98615c2aefe92fe5b5e0 Mon Sep 17 00:00:00 2001 From: bjornmp Date: Mon, 25 Sep 2023 00:32:43 +0200 Subject: [PATCH] Enforce that custom nodes keep their original type Enforce that custom nodes and resources created via the "Create New Node" dialog, should permanently retain their original type (script). This means: - Type continuity: It should be impossible for the user to (accidentally) clear the original script of a custom node that was created via the "Create New Node" dialog. - Extensibility: The user should be able to extend custom types as usual (create a script that inherits the original type and replace the original script of that node with his own). However, if he then clears his extension-script from that node later on, the custom type should revert to its original script instead of becoming a non-scripted type. --- editor/editor_data.cpp | 2 + editor/editor_node.cpp | 5 ++ editor/editor_properties.cpp | 1 + editor/editor_resource_picker.cpp | 23 +++++- editor/editor_resource_picker.h | 5 ++ editor/scene_tree_dock.cpp | 121 ++++++++++++++++++++++++------ editor/scene_tree_dock.h | 1 + scene/property_utils.cpp | 10 +++ scene/scene_string_names.cpp | 2 + scene/scene_string_names.h | 2 + 10 files changed, 147 insertions(+), 25 deletions(-) diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index ee16c61c897..bb02172b1a8 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -547,6 +547,7 @@ Variant EditorData::instantiate_custom_type(const String &p_type, const String & if (n) { n->set_name(p_type); } + n->set_meta(SceneStringName(_custom_type_script), script); ((Object *)ob)->set_script(script); return ob; } @@ -1008,6 +1009,7 @@ Variant EditorData::script_class_instance(const String &p_class) { // Store in a variant to initialize the refcount if needed. Variant obj = ClassDB::instantiate(script->get_instance_base_type()); if (obj) { + Object::cast_to(obj)->set_meta(SceneStringName(_custom_type_script), script); obj.operator Object *()->set_script(script); } return obj; diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index d88fb134f16..e57328911dd 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4672,6 +4672,11 @@ void EditorNode::stop_child_process(OS::ProcessID p_pid) { Ref