Skip to content

Commit

Permalink
Fix reloading scripts already in use
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilderin committed Sep 18, 2024
1 parent 694d3c2 commit fafc608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ void Script::reload_from_file() {
set_source_code(rel->get_source_code());
set_last_modified_time(rel->get_last_modified_time());

reload();
// It's important to set p_keep_state to true in order to manage reloading tool scripts
// that are currently instantiated.
reload(true);
#else
Resource::reload_from_file();
#endif
Expand Down
9 changes: 8 additions & 1 deletion editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,14 @@ void EditorFileSystem::_update_script_documentation() {
// editor without being connected to the LSP server.
Ref<Resource> res = ResourceCache::get_ref(path);
if (res.is_valid()) {
res->reload_from_file();
Ref<Script> scr = res;
if (scr.is_valid()) {
// Scripts are reloaded via the script editor if they are currently opened.
if (ScriptEditor::get_singleton()->get_open_scripts().has(scr)) {
continue;
}
scr->reload_from_file();
}
}
Ref<Script> scr = ResourceLoader::load(path);
if (scr.is_null()) {
Expand Down

0 comments on commit fafc608

Please sign in to comment.