diff --git a/doc/classes/EditorSettings.xml b/doc/classes/EditorSettings.xml
index c4aa05fcb31..8b7971c0a8a 100644
--- a/doc/classes/EditorSettings.xml
+++ b/doc/classes/EditorSettings.xml
@@ -1252,6 +1252,10 @@
If [code]true[/code], converts indentation to match the script editor's indentation settings when saving a script. See also [member text_editor/behavior/indent/type].
+
+ If [code]true[/code], when dropping a [Resource] file to script editor while [kbd]Ctrl[/kbd] is held, the resource will be preloaded with a UID. If [code]false[/code], the resource will be preloaded with a path.
+ When you hold [kbd]Ctrl+Shift[/kbd], the behavior is reversed.
+
If [code]true[/code], opening a scene automatically opens the script attached to the root node, or the topmost node if the root has no script.
diff --git a/editor/editor_property_name_processor.cpp b/editor/editor_property_name_processor.cpp
index a0baad7a141..f2e7161fca5 100644
--- a/editor/editor_property_name_processor.cpp
+++ b/editor/editor_property_name_processor.cpp
@@ -300,6 +300,7 @@ EditorPropertyNameProcessor::EditorPropertyNameProcessor() {
capitalize_string_remaps["us"] = U"(µs)"; // Unit.
capitalize_string_remaps["usb"] = "USB";
capitalize_string_remaps["usec"] = U"(µsec)"; // Unit.
+ capitalize_string_remaps["uid"] = "UID";
capitalize_string_remaps["uuid"] = "UUID";
capitalize_string_remaps["uv"] = "UV";
capitalize_string_remaps["uv1"] = "UV1";
diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp
index 93f280c1370..f4bdfa57502 100644
--- a/editor/editor_settings.cpp
+++ b/editor/editor_settings.cpp
@@ -718,6 +718,7 @@ void EditorSettings::_load_defaults(Ref p_extra_config) {
_initial_set("text_editor/behavior/files/auto_reload_scripts_on_external_change", false);
_initial_set("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true);
_initial_set("text_editor/behavior/files/open_dominant_script_on_scene_change", false, true);
+ _initial_set("text_editor/behavior/files/drop_preload_resources_as_uid", true, true);
// Behavior: Documentation
_initial_set("text_editor/behavior/documentation/enable_tooltips", true, true);
diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp
index 70a2960f086..65fe13e5ba4 100644
--- a/editor/plugins/script_text_editor.cpp
+++ b/editor/plugins/script_text_editor.cpp
@@ -1928,8 +1928,14 @@ static String _quote_drop_data(const String &str) {
return escaped.quote(using_single_quotes ? "'" : "\"");
}
-static String _get_dropped_resource_line(const Ref &p_resource, bool p_create_field) {
- const String &path = p_resource->get_path();
+static String _get_dropped_resource_line(const Ref &p_resource, bool p_create_field, bool p_allow_uid) {
+ String path = p_resource->get_path();
+ if (p_allow_uid) {
+ ResourceUID::ID id = ResourceLoader::get_resource_uid(path);
+ if (id != ResourceUID::INVALID_ID) {
+ path = ResourceUID::get_singleton()->id_to_text(id);
+ }
+ }
const bool is_script = ClassDB::is_parent_class(p_resource->get_class(), "Script");
if (!p_create_field) {
@@ -1938,7 +1944,7 @@ static String _get_dropped_resource_line(const Ref &p_resource, bool p
String variable_name = p_resource->get_name();
if (variable_name.is_empty()) {
- variable_name = path.get_file().get_basename();
+ variable_name = p_resource->get_path().get_file().get_basename();
}
if (is_script) {
@@ -1969,6 +1975,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
String text_to_drop;
const bool drop_modifier_pressed = Input::get_singleton()->is_key_pressed(Key::CMD_OR_CTRL);
+ const bool allow_uid = Input::get_singleton()->is_key_pressed(Key::SHIFT) != bool(EDITOR_GET("text_editor/behavior/files/drop_preload_resources_as_uid"));
const String &line = te->get_line(drop_at_line);
const bool is_empty_line = line_will_be_empty || line.is_empty() || te->get_first_non_whitespace_column(drop_at_line) == line.length();
@@ -1991,7 +1998,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
String warning = TTR("Preloading internal resources is not supported.");
EditorToaster::get_singleton()->popup_str(warning, EditorToaster::SEVERITY_ERROR);
} else {
- text_to_drop = _get_dropped_resource_line(resource, is_empty_line);
+ text_to_drop = _get_dropped_resource_line(resource, is_empty_line, allow_uid);
}
} else {
text_to_drop = _quote_drop_data(path);
@@ -2010,7 +2017,7 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data
resource.instantiate();
resource->set_path_cache(path);
}
- parts.append(_get_dropped_resource_line(resource, is_empty_line));
+ parts.append(_get_dropped_resource_line(resource, is_empty_line, allow_uid));
} else {
parts.append(_quote_drop_data(path));
}