summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:11:53 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:11:53 +0200
commit9f70823eecdbbb5bee69f1fcd323122ead68defa (patch)
tree3a8c8fc2717ca4999ff786ce223d2c0284d8612c /modules
parent330fca1ffd0ba2fa7fc8ee270ab47fed645fd9b6 (diff)
parent56365183587a17999d52ea429ecdaa0fa9e623cf (diff)
downloadredot-engine-9f70823eecdbbb5bee69f1fcd323122ead68defa.tar.gz
Merge pull request #94012 from KoBeWi/reload_everything_to_update_one_line
Allow live reloading of built-in scripts
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 7bf5e946fb..c72755642b 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -53,6 +53,7 @@
#include "core/io/file_access_encrypted.h"
#include "core/os/os.h"
+#include "scene/resources/packed_scene.h"
#include "scene/scene_string_names.h"
#ifdef TOOLS_ENABLED
@@ -2503,7 +2504,7 @@ void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload
SelfList<GDScript> *elem = script_list.first();
while (elem) {
// Scripts will reload all subclasses, so only reload root scripts.
- if (elem->self()->is_root_script() && elem->self()->get_path().is_resource_file()) {
+ if (elem->self()->is_root_script() && !elem->self()->get_path().is_empty()) {
scripts.push_back(Ref<GDScript>(elem->self())); //cast to gdscript to avoid being erased by accident
}
elem = elem->next();
@@ -2571,7 +2572,19 @@ void GDScriptLanguage::reload_scripts(const Array &p_scripts, bool p_soft_reload
for (KeyValue<Ref<GDScript>, HashMap<ObjectID, List<Pair<StringName, Variant>>>> &E : to_reload) {
Ref<GDScript> scr = E.key;
print_verbose("GDScript: Reloading: " + scr->get_path());
- scr->load_source_code(scr->get_path());
+ if (scr->is_built_in()) {
+ // TODO: It would be nice to do it more efficiently than loading the whole scene again.
+ Ref<PackedScene> scene = ResourceLoader::load(scr->get_path().get_slice("::", 0), "", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP);
+ ERR_CONTINUE(scene.is_null());
+
+ Ref<SceneState> state = scene->get_state();
+ Ref<GDScript> fresh = state->get_sub_resource(scr->get_path());
+ ERR_CONTINUE(fresh.is_null());
+
+ scr->set_source_code(fresh->get_source_code());
+ } else {
+ scr->load_source_code(scr->get_path());
+ }
scr->reload(p_soft_reload);
//restore state if saved