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

Script editor soft-reload button doesn't seem to do anything #26326

Closed
KoBeWi opened this issue Feb 26, 2019 · 4 comments · Fixed by #55134
Closed

Script editor soft-reload button doesn't seem to do anything #26326

KoBeWi opened this issue Feb 26, 2019 · 4 comments · Fixed by #55134

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Feb 26, 2019

Godot version:
3.1 beta8

Issue description:
Menu option "Soft reload script" does nothing. At first I though it's an issue with built-in scripts, as when you change scene externally, there's no way to reload a built-in script (there should be IMO), other than reloading whole scene ofc.
But if you disable auto-reload of scripts and change a script externally and return to editor, you get a warning that script got changed. When you cancel the warning, there's no way reload script other than re-focusing editor. The soft reload button does nothing.

Steps to reproduce:

  1. Disable "Auto Reload Scripts On External Change" in editor settings
  2. Open a script in Godot
  3. Change it externally
  4. Focus on Godot
  5. Cancel the external change warning
  6. Try to reload the script without unfocusing Godot

Good luck ;)

@KoBeWi
Copy link
Member Author

KoBeWi commented Jun 5, 2019

After some testing I discovered that this option will "commit" changes to script resource without saving the file. The only actual use is to "reload" tool scripts, so they update without being saved (no idea how would that be useful).

Is this option important? Maybe it could be removed or renamed, so it's less confusing? Or have functionality changed?

@Calinou
Copy link
Member

Calinou commented Apr 29, 2020

Bump. Are there any use cases where reloading a script without saving it is desired? cc @vnen

@evanrinehart
Copy link

Though I noticed soft reload does do something. Break things after you do a renaming of the file.

#49369

@KoBeWi
Copy link
Member Author

KoBeWi commented Nov 19, 2021

The reload option was added in f8f3066
Originally it was called Reload Tool Script and Reload Tool Script (Soft). The former was removed (from menu, enum value still exists), the latter was renamed to Soft Reload Script.

Soft reload is the same as reload, but it passes true to keep_state parameter. Which means that if you soft-reload a script, it will recompile the code, but keep variable values. Which is great especially for editor plugins, because it solves the ever-recurring problem of disappearing references. The problem is that saving a script will do a hard reload, which will kill all script instances and reset all variables. Interestingly, editor plugins actually have a special case for reloading thta should prevent this

bool soft = p_soft || scr->get_instance_base_type() == "EditorPlugin"; //always soft-reload editor plugins

but it doesn't seem to work. (upon investigation, seems like hard-reloading uses a different method)

And fun fact is that built-in tool scripts don't clear instances properly and can't be hard-reloaded, so while implementing #54662 I made them soft-reload. Which means that using built-in tool scripts is right now better option than external tool scripts🙃

Script reloading only affects tool scripts (because it reloads script instances and only tool scripts run in editor), hence renaming the menu option only brought confusion. IMO all scripts should default to soft-reloading (especially upon saving), which will solve many tool-script issues; and the soft-reload option should be replaced by hard-reload instead, and it should mention tool scripts again (actually, we could even disable it for non-tool scripts).

EDIT:
Most related issue, that also links other issues: godotengine/godot-proposals#1659
If soft-reloading was default, all of them would get resolved.
Also I confirmed that soft-reloading manually via the menu option does work on tools/plugins, so something is wrong in script editor logic somewhere.

EDIT2:
The hard-reload-on-save and menu rename was introduced here: 45443a1 (probably the logic is now outdated)

@akien-mga akien-mga added this to the 4.0 milestone May 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants