Delegate reloading to ScriptLanguage

This commit is contained in:
Chris Cranford
2026-01-19 20:36:31 -05:00
parent 8120fb1242
commit c7ed47234e
2 changed files with 7 additions and 20 deletions
+5 -20
View File
@@ -189,27 +189,12 @@ void Script::_bind_methods() {
void Script::reload_from_file() {
#ifdef TOOLS_ENABLED
// Replicates how the ScriptEditor reloads script resources, which generally handles it.
// However, when scripts are to be reloaded but aren't open in the internal editor, we go through here instead.
const Ref<Script> rel = ResourceLoader::load(ResourceLoader::path_remap(get_path()), get_class(), ResourceFormatLoader::CACHE_MODE_IGNORE);
if (rel.is_null()) {
return;
if (Engine::get_singleton()->is_editor_hint() && is_tool()) {
get_language()->reload_tool_script(this, true);
} else {
Array scripts = { this };
get_language()->reload_scripts(scripts, true);
}
set_source_code(rel->get_source_code());
set_last_modified_time(rel->get_last_modified_time());
// Only reload the script when there are no compilation errors to prevent printing the error messages twice.
if (rel->is_valid()) {
if (Engine::get_singleton()->is_editor_hint() && is_tool()) {
get_language()->reload_tool_script(this, true);
} else {
// It's important to set p_keep_state to true in order to manage reloading scripts
// that are currently instantiated.
reload(true);
}
}
#else
Resource::reload_from_file();
#endif