Browse Source

Update cached singletons when reloading GDScripts

(cherry picked from commit 8cdbec0434fd95c303c670985406224c2c6b5232)
DmitriySalnikov 1 year ago
parent
commit
2b3a8f060a
1 changed files with 13 additions and 0 deletions
  1. 13 0
      modules/gdscript/gdscript.cpp

+ 13 - 0
modules/gdscript/gdscript.cpp

@@ -2329,6 +2329,19 @@ void GDScriptLanguage::reload_all_scripts() {
 			}
 			elem = elem->next();
 		}
+
+#ifdef TOOLS_ENABLED
+		if (Engine::get_singleton()->is_editor_hint()) {
+			// Reload all pointers to existing singletons so that tool scripts can work with the reloaded extensions.
+			List<Engine::Singleton> singletons;
+			Engine::get_singleton()->get_singletons(&singletons);
+			for (const Engine::Singleton &E : singletons) {
+				if (globals.has(E.name)) {
+					_add_global(E.name, E.ptr);
+				}
+			}
+		}
+#endif
 	}
 
 	//as scripts are going to be reloaded, must proceed without locking here