diff options
author | kobewi <kobewi4e@gmail.com> | 2022-12-28 13:56:53 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2022-12-28 15:40:45 +0100 |
commit | f2367e078200dadddc00a2738ba7efbe1b1403bf (patch) | |
tree | f7ae4384dc5054ac3fd7260b4d108838401be0aa | |
parent | 5674fa04aeb44a0d9cf48073fe2be25d1b804acf (diff) |
Retry loading addons after filesystem scan
-rw-r--r-- | doc/classes/EditorFileSystem.xml | 5 | ||||
-rw-r--r-- | editor/editor_file_system.cpp | 2 | ||||
-rw-r--r-- | editor/editor_node.cpp | 17 | ||||
-rw-r--r-- | editor/editor_node.h | 2 |
4 files changed, 26 insertions, 0 deletions
diff --git a/doc/classes/EditorFileSystem.xml b/doc/classes/EditorFileSystem.xml index e8df6ae7fe..cddf3662aa 100644 --- a/doc/classes/EditorFileSystem.xml +++ b/doc/classes/EditorFileSystem.xml @@ -96,6 +96,11 @@ Emitted if at least one resource is reloaded when the filesystem is scanned. </description> </signal> + <signal name="script_classes_updated"> + <description> + Emitted when the list of global script classes gets updated. + </description> + </signal> <signal name="sources_changed"> <param index="0" name="exist" type="bool" /> <description> diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index b98480b594..50dce38f69 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1527,6 +1527,7 @@ void EditorFileSystem::update_script_classes() { ScriptServer::save_global_classes(); EditorNode::get_editor_data().script_class_save_icon_paths(); + emit_signal("script_classes_updated"); // Rescan custom loaders and savers. // Doing the following here because the `filesystem_changed` signal fires multiple times and isn't always followed by script classes update. @@ -2417,6 +2418,7 @@ void EditorFileSystem::_bind_methods() { ClassDB::bind_method(D_METHOD("reimport_files", "files"), &EditorFileSystem::reimport_files); ADD_SIGNAL(MethodInfo("filesystem_changed")); + ADD_SIGNAL(MethodInfo("script_classes_updated")); ADD_SIGNAL(MethodInfo("sources_changed", PropertyInfo(Variant::BOOL, "exist"))); ADD_SIGNAL(MethodInfo("resources_reimported", PropertyInfo(Variant::PACKED_STRING_ARRAY, "resources"))); ADD_SIGNAL(MethodInfo("resources_reload", PropertyInfo(Variant::PACKED_STRING_ARRAY, "resources"))); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 01e605880c..923ff01dec 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -630,6 +630,10 @@ void EditorNode::_notification(int p_what) { set_addon_plugin_enabled(addons[i], true); } _initializing_plugins = false; + + if (!pending_addons.is_empty()) { + EditorFileSystem::get_singleton()->connect("script_classes_updated", callable_mp(this, &EditorNode::_enable_pending_addons)); + } } RenderingServer::get_singleton()->viewport_set_disable_2d(get_scene_root()->get_viewport_rid(), true); @@ -3487,6 +3491,12 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, // Errors in the script cause the base_type to be an empty StringName. if (scr->get_instance_base_type() == StringName()) { + if (_initializing_plugins) { + // However, if it happens during initialization, waiting for file scan might help. + pending_addons.push_back(p_addon); + return; + } + show_warning(vformat(TTR("Unable to load addon script from path: '%s'. This might be due to a code error in that script.\nDisabling the addon at '%s' to prevent further errors."), script_path, addon_path)); _remove_plugin_from_enabled(addon_path); return; @@ -4394,6 +4404,13 @@ void EditorNode::_build_icon_type_cache() { } } +void EditorNode::_enable_pending_addons() { + for (uint32_t i = 0; i < pending_addons.size(); i++) { + set_addon_plugin_enabled(pending_addons[i], true); + } + pending_addons.clear(); +} + void EditorNode::_file_dialog_register(FileDialog *p_dialog) { singleton->file_dialogs.insert(p_dialog); } diff --git a/editor/editor_node.h b/editor/editor_node.h index 950970379d..a4dd7a44b5 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -292,6 +292,7 @@ private: Vector<EditorPlugin *> editor_plugins; bool _initializing_plugins = false; HashMap<String, EditorPlugin *> addon_name_to_plugin; + LocalVector<String> pending_addons; PanelContainer *scene_root_parent = nullptr; Control *theme_base = nullptr; @@ -535,6 +536,7 @@ private: static void _resource_loaded(Ref<Resource> p_resource, const String &p_path); void _build_icon_type_cache(); + void _enable_pending_addons(); void _dialog_action(String p_file); |