-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Always soft-reload scripts #55134
Always soft-reload scripts #55134
Conversation
As far as I remember from a discussion with @reduz long ago, both hard reload and soft reload should keep state; with the only difference being hard reload destroys and recreates instances restoring their state, meanwhile soft reload keeps the existing instances. |
What is the purpose of destroying script instances? The behavior of hard-reload is weird, seems like you actually need to remove the instances yourself, otherwise the reloading will fail, because the script is in use. Also, state preserving is conditionally disabled for hard-reload, so it looks intended. If this is really a bug, then it's at least 5 years old 🙃 btw when discussed during meeting, reduz's concern was that soft-reload will keep variable list, so if you add a new variable or delete one, it won't work properly. I tested this and the script will detect new variables properly, but they will have |
For GDScript, I don't know. For C#, it's the only way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved in PR review meeting, we're not 100% sure that hard reload is no longer useful (aside from C# needs where it's hardcoded - this PR only impacts the builtin script editor), but it makes sense at least to default to soft reload. We'll see if anyone comes up with a use case for reintroducing hard reload options.
Thanks! |
See #26326 (comment) for context.
This PR makes all scripts soft-reload by default. This prevents script variables from being cleared upon save etc. I didn't find any drawbacks of using soft-reloading. The only case where hard-reload is stil used is when running EditorScript.
The "Soft Reload Script" menu option was renamed to "Soft Reload Tool Script" and only works on tool scripts (technically it always only worked on tool scripts, but now there is a proper error message). I left it out, because apparently we have an editor setting for auto-reloading scripts on save, which can be disabled. If we ever remove this setting, soft-reload menu option will become unnecessary and could be removed too.
Also I considered adding menu option for hard-reloading, but apparently it requires that no script instance exists and the option almost always fails when used. There is a
reload_tool_script
method that could be used, but only GDScript has it.Resolves #26326
Resolves godotengine/godot-proposals#1659 (fixes the original problem)
Fixes #5969
Closes #6276 (last issue)
2 more related proposals, but not sure if it resolves them:
godotengine/godot-proposals#1012
godotengine/godot-proposals#2365