Delegate reloading to ScriptLanguage
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user