Repository: godotengine/godot
File: editor/settings/editor_autoload_settings.cpp (C++)

Code before:
			ERR_FAIL_COND_V_MSG(!scr->is_valid(), nullptr, vformat("Failed to create an autoload, script '%s' is not compiling.", p_path));

			StringName ibt = scr->get_instance_base_type();
			bool valid_type = ClassDB::is_parent_class(ibt, "Node");
			ERR_FAIL_COND_V_MSG(!valid_type, nullptr, vformat("Failed to create an autoload, script '%s' does not inherit from 'Node'.", p_path));

			Object *obj = ClassDB::instantiate(ibt);
			ERR_FAIL_NULL_V_MSG(obj, nullptr, vformat("Failed to create an autoload, cannot instantiate '%s'.", ibt));

			n = Object::cast_to<Node>(obj);
			n->set_script(scr);
		}
	}

	ERR_FAIL_NULL_V_MSG(n, nullptr, vformat("Failed to create an autoload, path is not pointing to a scene or a script: %s.", p_path));

	return n;
}

void EditorAutoloadSettings::init_autoloads() {
	bool clear_fs = false;
	for (AutoloadInfo &info : autoload_cache) {
		// Convert UID to actual Path (If Possible)
		if (info.path.begins_with("uid://")) {
			info.path = ResourceUID::get_singleton()->get_id_path(ResourceUID::get_singleton()->text_to_id(info.path));
		}

		if (!FileAccess::exists(info.path)) {
			clear_fs = true;
		}

		info.node = _create_autoload(info.path);

		if (info.node) {
			Ref<Script> scr = info.node->get_script();
			info.in_editor = scr.is_valid() && scr->is_tool();
			info.node->set_name(info.name);
		}

		if (info.is_singleton) {
			for (int i = 0; i < ScriptServer::get_language_count(); i++) {
				ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node);
			}
		}

		if (!info.is_singleton && !info.in_editor && info.node != nullptr) {
			memdelete(info.node);
			info.node = nullptr;
		}
	}


Review comment (suggestion):
If anything
```suggestion
		info.path = ResourceUID.ensure_path(info.path);
```
Although FileAccess supports UIDs, so you don't need to convert it.

Code after:
			ERR_FAIL_COND_V_MSG(!scr->is_valid(), nullptr, vformat("Failed to create an autoload, script '%s' is not compiling.", p_path));

			StringName ibt = scr->get_instance_base_type();
			bool valid_type = ClassDB::is_parent_class(ibt, "Node");
			ERR_FAIL_COND_V_MSG(!valid_type, nullptr, vformat("Failed to create an autoload, script '%s' does not inherit from 'Node'.", p_path));

			Object *obj = ClassDB::instantiate(ibt);
			ERR_FAIL_NULL_V_MSG(obj, nullptr, vformat("Failed to create an autoload, cannot instantiate '%s'.", ibt));

			n = Object::cast_to<Node>(obj);
			n->set_script(scr);
		}
	}

	ERR_FAIL_NULL_V_MSG(n, nullptr, vformat("Failed to create an autoload, path is not pointing to a scene or a script: %s.", p_path));

	return n;
}

void EditorAutoloadSettings::init_autoloads() {
	for (AutoloadInfo &info : autoload_cache) {
		info.node = _create_autoload(ResourceUID::ensure_path(info.path));

		if (info.node) {
			Ref<Script> scr = info.node->get_script();
			info.in_editor = scr.is_valid() && scr->is_tool();
			info.node->set_name(info.name);
		}

		if (info.is_singleton) {
			for (int i = 0; i < ScriptServer::get_language_count(); i++) {
				ScriptServer::get_language(i)->add_named_global_constant(info.name, info.node);
			}
		}

		if (!info.is_singleton && !info.in_editor && info.node != nullptr) {
			memdelete(info.node);
			info.node = nullptr;
		}
	}

	for (const AutoloadInfo &info : autoload_cache) {
		if (info.node && info.in_editor) {
			// It's important to add the node without deferring because code in plugins or tool scripts
			// could use the autoload node when they are enabled.
			get_tree()->get_root()->add_child(info.node);
		}
	}
}

void EditorAutoloadSettings::update_autoload() {