Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotreload of externally edited GDScript #20910

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions editor/plugins/script_text_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,9 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo
uint64_t date = FileAccess::get_modified_time(script->get_path());

if (last_date != date) {
bool soft = script->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins

Ref<Script> rel_script = ResourceLoader::load(script->get_path(), script->get_class(), true);
ERR_CONTINUE(!rel_script.is_valid());
script->set_source_code(rel_script->get_source_code());
script->set_last_modified_time(rel_script->get_last_modified_time());
script->update_exports();
script->get_language()->reload_tool_script(script, soft);
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,17 @@ void GDScriptLanguage::reload_tool_script(const Ref<Script> &p_script, bool p_so
for (Map<Ref<GDScript>, Map<ObjectID, List<Pair<StringName, Variant> > > >::Element *E = to_reload.front(); E; E = E->next()) {

Ref<GDScript> scr = E->key();
Ref<Script> rel_scr = ResourceLoader::load(scr->get_path(), scr->get_class(), true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may break scripts that were edited in the built-in editor but not saved? I think there has to be a different way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still unresolved @T4g1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm finally back into gamedev, I'll work on that this week.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at it, this fix is no longer working and I don't have a good enough understanding of the engine to fix it right now. I doubt that I will dive more on this part as I do not use an external editor anymore but here is where I'm stuck: https://github.com/godotengine/godot/blob/master/editor/plugins/script_editor_plugin.cpp#L785 So we keep the edited script and we then want to script->reload() it, problem is, "has_instances" is true in GDScript::reload so the fail condition triggers: What instances does and why it needs to be empty for reload is unclear for me but depending on that, one could: a) discard it before reload, b) clear it and re-populate it after reload, c) remove the fail condition on has_instances

ERR_CONTINUE(!rel_scr.is_valid());
scr->set_source_code(rel_scr->get_source_code());

#ifdef TOOLS_ENABLED

scr->set_last_modified_time(rel_scr->get_last_modified_time());

#endif

scr->update_exports();
scr->reload(p_soft_reload);

//restore state if saved
Expand Down