@@ -538,6 +538,10 @@ void CSharpLanguage::frame() {
538538 if (gdmono && gdmono->is_runtime_initialized () && GDMonoCache::godot_api_cache_updated) {
539539 GDMonoCache::managed_callbacks.ScriptManagerBridge_FrameCallback ();
540540 }
541+
542+ #ifdef TOOLS_ENABLED
543+ _flush_filesystem_updates ();
544+ #endif
541545}
542546
543547struct CSharpScriptDepSort {
@@ -1072,6 +1076,47 @@ bool CSharpLanguage::debug_break(const String &p_error, bool p_allow_continue) {
10721076}
10731077
10741078#ifdef TOOLS_ENABLED
1079+ void CSharpLanguage::_queue_for_filesystem_update (String p_script_path) {
1080+ if (!Engine::get_singleton ()->is_editor_hint ()) {
1081+ return ;
1082+ }
1083+
1084+ if (p_script_path.is_empty ()) {
1085+ return ;
1086+ }
1087+
1088+ pending_file_system_update_paths.push_back (p_script_path);
1089+ }
1090+
1091+ void CSharpLanguage::_flush_filesystem_updates () {
1092+ if (!Engine::get_singleton ()->is_editor_hint ()) {
1093+ return ;
1094+ }
1095+
1096+ if (pending_file_system_update_paths.is_empty ()) {
1097+ return ;
1098+ }
1099+
1100+ // If the EditorFileSystem singleton is available, update the files;
1101+ // otherwise, the files will be updated when the singleton becomes available.
1102+ EditorFileSystem *efs = EditorFileSystem::get_singleton ();
1103+ if (!efs) {
1104+ pending_file_system_update_paths.clear ();
1105+ return ;
1106+ }
1107+
1108+ // Required to prevent EditorProgress within EditorFileSystem from calling this while it is already flushing
1109+ if (is_flushing_filesystem_updates) {
1110+ return ;
1111+ }
1112+ is_flushing_filesystem_updates = true ;
1113+
1114+ efs->update_files (pending_file_system_update_paths);
1115+
1116+ is_flushing_filesystem_updates = false ;
1117+ pending_file_system_update_paths.clear ();
1118+ }
1119+
10751120void CSharpLanguage::_editor_init_callback () {
10761121 // Load GodotTools and initialize GodotSharpEditor
10771122
@@ -2243,12 +2288,7 @@ void CSharpScript::reload_registered_script(Ref<CSharpScript> p_script) {
22432288 p_script->_update_exports ();
22442289
22452290#ifdef TOOLS_ENABLED
2246- // If the EditorFileSystem singleton is available, update the file;
2247- // otherwise, the file will be updated when the singleton becomes available.
2248- EditorFileSystem *efs = EditorFileSystem::get_singleton ();
2249- if (efs && !p_script->get_path ().is_empty ()) {
2250- efs->update_file (p_script->get_path ());
2251- }
2291+ CSharpLanguage::get_singleton ()->_queue_for_filesystem_update (p_script->get_path ());
22522292#endif
22532293}
22542294
@@ -2621,12 +2661,7 @@ Error CSharpScript::reload(bool p_keep_state) {
26212661 _update_exports ();
26222662
26232663#ifdef TOOLS_ENABLED
2624- // If the EditorFileSystem singleton is available, update the file;
2625- // otherwise, the file will be updated when the singleton becomes available.
2626- EditorFileSystem *efs = EditorFileSystem::get_singleton ();
2627- if (efs) {
2628- efs->update_file (script_path);
2629- }
2664+ CSharpLanguage::get_singleton ()->_queue_for_filesystem_update (script_path);
26302665#endif
26312666 }
26322667
0 commit comments