Repository: godotengine/godot
File: editor/plugins/node_3d_editor_plugin.cpp (C++)

Code before:

			List<String> scene_extensions;
			ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
			List<String> mesh_extensions;
			ResourceLoader::get_recognized_extensions_for_type("Mesh", &mesh_extensions);

			for (int i = 0; i < files.size(); i++) {
				if (mesh_extensions.find(files[i].get_extension()) || scene_extensions.find(files[i].get_extension())) {
					RES res = ResourceLoader::load(files[i]);
					if (res.is_null()) {
						continue;
					}

					String type = res->get_class();
					if (type == "PackedScene") {
						Ref<PackedScene> sdata = ResourceLoader::load(files[i]);
						Node *instantiated_scene = sdata->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE);
						if (!instantiated_scene) {
							continue;
						}
						memdelete(instantiated_scene);
					} else if (ClassDB::is_parent_class(type, "Mesh")) {
						Ref<Mesh> mesh = ResourceLoader::load(files[i]);
						if (!mesh.is_valid()) {
							continue;
						}
					} else {
						continue;
					}
					can_instantiate = true;
					break;
				}
			}
			if (can_instantiate) {
				_create_preview(files);
			}
		}
	} else {
		can_instantiate = true;
	}

	if (can_instantiate) {
		Transform3D global_transform = Transform3D(Basis(), _get_instance_position(p_point));
		preview_node->set_global_transform(global_transform);
	}

	return can_instantiate;
}

void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
	if (!can_drop_data_fw(p_point, p_data, p_from)) {

Review comment (suggestion):
Removed this as this seemed to be a no-op. We already check that `res` isn't null above, which means that it could be loaded properly. If it could be loaded, and it is of class Mesh, then it could be loaded as a Mesh... so there doesn't seem to be anything to validate.

Code after:

			List<String> scene_extensions;
			ResourceLoader::get_recognized_extensions_for_type("PackedScene", &scene_extensions);
			List<String> mesh_extensions;
			ResourceLoader::get_recognized_extensions_for_type("Mesh", &mesh_extensions);

			for (int i = 0; i < files.size(); i++) {
				// Check if dragged files with mesh or scene extension can be created at least once.
				if (mesh_extensions.find(files[i].get_extension()) || scene_extensions.find(files[i].get_extension())) {
					RES res = ResourceLoader::load(files[i]);
					if (res.is_null()) {
						continue;
					}
					Ref<PackedScene> scn = res;
					if (scn.is_valid()) {
						Node *instantiated_scene = scn->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE);
						if (!instantiated_scene) {
							continue;
						}
						memdelete(instantiated_scene);
					} else {
						continue;
					}
					can_instantiate = true;
					break;
				}
			}
			if (can_instantiate) {
				_create_preview(files);
			}
		}
	} else {
		can_instantiate = true;
	}

	if (can_instantiate) {
		Transform3D global_transform = Transform3D(Basis(), _get_instance_position(p_point));
		preview_node->set_global_transform(global_transform);
	}

	return can_instantiate;
}

void Node3DEditorViewport::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
	if (!can_drop_data_fw(p_point, p_data, p_from)) {
		return;
	}

	bool is_shift = Input::get_singleton()->is_key_pressed(Key::SHIFT);
	bool is_ctrl = Input::get_singleton()->is_key_pressed(Key::CTRL);