diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 1127cbcfde9..f207418f716 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -6928,8 +6928,7 @@ EditorNode::EditorNode() { { // Register importers at the beginning, so dialogs are created with the right extensions. - Ref import_texture; - import_texture.instantiate(); + Ref import_texture = memnew(ResourceImporterTexture(true)); ResourceFormatImporter::get_singleton()->add_importer(import_texture); Ref import_cubemap; @@ -6947,8 +6946,7 @@ EditorNode::EditorNode() { import_cubemap_array->set_mode(ResourceImporterLayeredTexture::MODE_CUBEMAP_ARRAY); ResourceFormatImporter::get_singleton()->add_importer(import_cubemap_array); - Ref import_3d; - import_3d.instantiate(); + Ref import_3d = memnew(ResourceImporterLayeredTexture(true)); import_3d->set_mode(ResourceImporterLayeredTexture::MODE_3D); ResourceFormatImporter::get_singleton()->add_importer(import_3d); @@ -6988,12 +6986,10 @@ EditorNode::EditorNode() { import_shader_file.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_shader_file); - Ref import_scene; - import_scene.instantiate(); + Ref import_scene = memnew(ResourceImporterScene(false, true)); ResourceFormatImporter::get_singleton()->add_importer(import_scene); - Ref import_animation; - import_animation = Ref(memnew(ResourceImporterScene(true))); + Ref import_animation = memnew(ResourceImporterScene(true, true)); ResourceFormatImporter::get_singleton()->add_importer(import_animation); { diff --git a/editor/import/resource_importer_layered_texture.cpp b/editor/import/resource_importer_layered_texture.cpp index 3c27864eff7..46882e95cb6 100644 --- a/editor/import/resource_importer_layered_texture.cpp +++ b/editor/import/resource_importer_layered_texture.cpp @@ -474,12 +474,19 @@ bool ResourceImporterLayeredTexture::are_import_settings_valid(const String &p_p ResourceImporterLayeredTexture *ResourceImporterLayeredTexture::singleton = nullptr; -ResourceImporterLayeredTexture::ResourceImporterLayeredTexture() { - singleton = this; +ResourceImporterLayeredTexture::ResourceImporterLayeredTexture(bool p_singleton) { + // This should only be set through the EditorNode. + if (p_singleton) { + singleton = this; + } + mode = MODE_CUBEMAP; } ResourceImporterLayeredTexture::~ResourceImporterLayeredTexture() { + if (singleton == this) { + singleton = nullptr; + } } void ResourceImporterLayeredTexture::_check_compress_ctex(const String &p_source_file, Ref r_texture_import) { diff --git a/editor/import/resource_importer_layered_texture.h b/editor/import/resource_importer_layered_texture.h index 52fd37639d9..5a21651de33 100644 --- a/editor/import/resource_importer_layered_texture.h +++ b/editor/import/resource_importer_layered_texture.h @@ -119,7 +119,7 @@ public: void set_mode(Mode p_mode) { mode = p_mode; } - ResourceImporterLayeredTexture(); + ResourceImporterLayeredTexture(bool p_singleton = false); ~ResourceImporterLayeredTexture(); }; diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index b0291f3a938..2e422d8c270 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -2607,15 +2607,28 @@ void ResourceImporterScene::ResourceImporterScene::show_advanced_options(const S SceneImportSettings::get_singleton()->open_settings(p_path, animation_importer); } -ResourceImporterScene::ResourceImporterScene(bool p_animation_import) { - if (p_animation_import) { - animation_singleton = this; - } else { - scene_singleton = this; +ResourceImporterScene::ResourceImporterScene(bool p_animation_import, bool p_singleton) { + // This should only be set through the EditorNode. + if (p_singleton) { + if (p_animation_import) { + animation_singleton = this; + } else { + scene_singleton = this; + } } + animation_importer = p_animation_import; } +ResourceImporterScene::~ResourceImporterScene() { + if (animation_singleton == this) { + animation_singleton = nullptr; + } + if (scene_singleton == this) { + scene_singleton = nullptr; + } +} + void ResourceImporterScene::add_importer(Ref p_importer, bool p_first_priority) { ERR_FAIL_COND(p_importer.is_null()); if (p_first_priority) { diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index a66fd034f82..7a07a5f6469 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -296,7 +296,8 @@ public: virtual bool can_import_threaded() const override { return false; } - ResourceImporterScene(bool p_animation_import = false); + ResourceImporterScene(bool p_animation_import = false, bool p_singleton = false); + ~ResourceImporterScene(); template static Vector> get_collision_shapes(const Ref &p_mesh, const M &p_options, float p_applied_root_scale); diff --git a/editor/import/resource_importer_texture.cpp b/editor/import/resource_importer_texture.cpp index 114ba5653a7..8eac5ec3232 100644 --- a/editor/import/resource_importer_texture.cpp +++ b/editor/import/resource_importer_texture.cpp @@ -789,10 +789,12 @@ bool ResourceImporterTexture::are_import_settings_valid(const String &p_path) co ResourceImporterTexture *ResourceImporterTexture::singleton = nullptr; -ResourceImporterTexture::ResourceImporterTexture() { - if (!singleton) { +ResourceImporterTexture::ResourceImporterTexture(bool p_singleton) { + // This should only be set through the EditorNode. + if (p_singleton) { singleton = this; } + CompressedTexture2D::request_3d_callback = _texture_reimport_3d; CompressedTexture2D::request_roughness_callback = _texture_reimport_roughness; CompressedTexture2D::request_normal_callback = _texture_reimport_normal; diff --git a/editor/import/resource_importer_texture.h b/editor/import/resource_importer_texture.h index c2bdbb6fa22..f2539a8f526 100644 --- a/editor/import/resource_importer_texture.h +++ b/editor/import/resource_importer_texture.h @@ -107,7 +107,7 @@ public: virtual bool are_import_settings_valid(const String &p_path) const override; virtual String get_import_settings_string() const override; - ResourceImporterTexture(); + ResourceImporterTexture(bool p_singleton = false); ~ResourceImporterTexture(); };