From 63674648fb97c297a0e516c2bbb108274721a21a Mon Sep 17 00:00:00 2001 From: Paul Joannon Date: Thu, 7 Mar 2024 20:19:05 +0100 Subject: [PATCH] Fix how scripts reload outside of ScriptEditor --- core/io/resource.cpp | 1 + core/object/script_language.cpp | 19 +++++++++++++++++++ core/object/script_language.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/core/io/resource.cpp b/core/io/resource.cpp index 7e8d0b43cd2..e2b43096e18 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -204,6 +204,7 @@ Error Resource::copy_from(const Ref &p_resource) { } return OK; } + void Resource::reload_from_file() { String path = get_path(); if (!path.is_resource_file()) { diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp index 693c6819d47..0b6c9c7057c 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -34,6 +34,7 @@ #include "core/core_string_names.h" #include "core/debugger/engine_debugger.h" #include "core/debugger/script_debugger.h" +#include "core/io/resource_loader.h" #include @@ -154,6 +155,24 @@ void Script::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_code", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_source_code", "get_source_code"); } +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