summaryrefslogtreecommitdiffstats
path: root/editor/editor_autoload_settings.cpp
diff options
context:
space:
mode:
authorHilderin <81109165+Hilderin@users.noreply.github.com>2024-05-24 01:30:16 -0400
committerHilderin <81109165+Hilderin@users.noreply.github.com>2024-06-25 18:33:07 -0400
commit39369db02985ea76d7f71e8f6232034b68a470f7 (patch)
tree190dc55635c77be26d8cf63532557878e6672542 /editor/editor_autoload_settings.cpp
parent6b281c0c07b07f2142b1fc8a6b3158091a9b124c (diff)
downloadredot-engine-39369db02985ea76d7f71e8f6232034b68a470f7.tar.gz
Fix synchronization of global class name
Diffstat (limited to 'editor/editor_autoload_settings.cpp')
-rw-r--r--editor/editor_autoload_settings.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp
index 545404ec8e..b62351256e 100644
--- a/editor/editor_autoload_settings.cpp
+++ b/editor/editor_autoload_settings.cpp
@@ -55,11 +55,6 @@ void EditorAutoloadSettings::_notification(int p_what) {
file_dialog->add_filter("*." + E);
}
- for (const AutoloadInfo &info : autoload_cache) {
- if (info.node && info.in_editor) {
- callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED);
- }
- }
browse_button->set_icon(get_editor_theme_icon(SNAME("Folder")));
} break;
@@ -419,6 +414,8 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
Ref<Script> scr = res;
if (scr.is_valid()) {
+ 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));
@@ -436,6 +433,35 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) {
return n;
}
+void EditorAutoloadSettings::init_autoloads() {
+ for (AutoloadInfo &info : autoload_cache) {
+ 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;
+ }
+ }
+
+ for (const AutoloadInfo &info : autoload_cache) {
+ if (info.node && info.in_editor) {
+ callable_mp((Node *)get_tree()->get_root(), &Node::add_child).call_deferred(info.node, false, Node::INTERNAL_MODE_DISABLED);
+ }
+ }
+}
+
void EditorAutoloadSettings::update_autoload() {
if (updating_autoload) {
return;
@@ -857,27 +883,6 @@ EditorAutoloadSettings::EditorAutoloadSettings() {
autoload_cache.push_back(info);
}
- for (AutoloadInfo &info : autoload_cache) {
- 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;
- }
- }
-
HBoxContainer *hbc = memnew(HBoxContainer);
add_child(hbc);