godot
godot copied to clipboard
GD Scripts changed externally not properly reloaded
Godot version
v4.0.alpha4.official [f47097973]
System information
macOS Monterey 12.2.1, Macbook Pro M1Max
Issue description
If a script is changed externally (e.g. in a different editor) Godot detects this and ask if the script should be reloaded. When clicking "reload" the editor window is not updated with the new changes. The old version is retained even if I close and reopen the (internal) code editor window. Selecting File >> Soft Reload Script is is also not updating the editor.
When running the project, the updated script is used so it seems to be an issue with the code editor only.
Steps to reproduce
- Create new project
- Add a scene and a node
- Attach a script to the node and save
- Edit the script in an external editor (e.g. vim, vscode)
- Switch back to Godot and click reload script
Minimal reproduction project
No response
@frklan Can you reproduce this in 3.4.3?
@frklan Can you reproduce this in 3.4.3?
No, 3.4.3 does not behave the same: when I change a script using another editor, that change is detected and show in the internal editor as soon as I switch back to Godot.
(Actually, I find that the automatic reload without confirmation is a much nicer experience. But that's a topic for another issue I guess 😸)
I ran into this as well, I've noticed that if there is a runtime error, Godot will pull up the old version of the script in the internal editor. If the user edits the file and saves when looking at the file inside of Godot it will remove any external edits made since the project was opened.
It looks like the reload that happens on project load works perfectly, but it isn't being updated while the project is still open.
I only just went to report this same issue, Ive experienced on every single version of Godot 4 that ive used... grabbing them from the precompiled area the alpha pages on the site links to.
Im doin 2 projects that have some shared code so on linux ive been using a soft-link folder and get notifs about the source being different constantly and just copy pasting the same code back into the file on each editor on both projects when i make a change lol -- It only properly reloads the changes if the project closes and reopens unfortunately x-x
I've had no real issues with vscode and Godot 4.0 until recently, probably alpha 13 or after. now though the internal editor doesn't seem to pickup any external changes to scripts. Edit - seems vscode is locking the file in my case and is not an issue with godot 4.
I can confirm that editing emacs is doing the same issue.
@SpiceyWolf @duchainer Can you test https://github.com/godotengine/godot/pull/59523?
I just tried this patch. It does not fix the issue for me - the script editor still shows the old file contents until godot is restarted.
It does detect the file changing, since editing the script file in Godot without saving, and then re-saving it externally, shows the "this file has changed" dialog (twice, actually!), but clicking "reload" there still leaves the script editor with outdated code.
EDIT: So it seems like ResourceFormatLoaderGDScript
just ignores the cache mode, does its own caching via GDScriptCache
, and that cache does not get invalidated for this case.
Same as @RedMser, https://github.com/godotengine/godot/pull/59523 does not fix it, though it might be because it needs to have open the file from godot to the external editor, which I often don't in my workflow.
https://github.com/godotengine/godot/pull/63224 does fix the issue for me though, so it should be mentioned. See below comparison video:
Rough Comparison video :
- Left: "Older" editor using https://github.com/godotengine/godot/pull/59523
- Right: "Newer" editor using https://github.com/godotengine/godot/pull/63224
- RightMost: External editor (emacs) You can see that it now works as expected : new_godot <-> external_editor , while the older godot does not reload at all.
After more than a week of that second patch https://github.com/godotengine/godot/pull/63224 being used by multiple devs on Windows, Mac and Linux, I can confirm that it works well @Calinou
This should be fixed by #63224, and in the case of lsp, will be fixed by #66405.
For text files, some extra work is required, and that might be a different issue.
Fixed by #63224 and #66405.
It's not 100% fixed, more like 90%. With LSP active, exports don't reflect updates when the editor is refocused. They update when the scene is ran, or (seemingly) when an LSP autocomplete thing pops up. I also caught a different strange hard-crash bug after turning LSP off and changing some export values (i might have to open a separate issue for that one) which I discovered right at the end of this video.
https://user-images.githubusercontent.com/32113038/192352599-3110746a-936d-44fc-bd6b-c9c2097b982d.mp4
The engine crashed with this output to stdout (i ran the scene two times, then after focusing the editor a 3rd time it crashed):
Running: /home/grendel/docs/cpp/godot-engine/bin/godot.linuxbsd.tools.x86_64 --path /home/grendel/docs/godot/4.0/TestJun9 --remote-debug tcp://127.0.0.1:6007 --editor-pid 21310 --position 384,216 res://main.tscn
Godot Engine v4.0.beta.custom_build.e406badaf - https://godotengine.org
Vulkan API 1.2.0 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1650 with Max-Q Design
10
what
Running: /home/grendel/docs/cpp/godot-engine/bin/godot.linuxbsd.tools.x86_64 --path /home/grendel/docs/godot/4.0/TestJun9 --remote-debug tcp://127.0.0.1:6007 --editor-pid 21310 --position 384,216 res://main.tscn
Godot Engine v4.0.beta.custom_build.e406badaf - https://godotengine.org
Vulkan API 1.2.0 - Using Vulkan Device #0: NVIDIA - NVIDIA GeForce GTX 1650 with Max-Q Design
100
what
terminate called after throwing an instance of 'std::system_error'
what(): Invalid argument
Aborted
Even after building the current version of master, Godot 4 still has issues with external editor.
Here are my steps to recreate this:
- Enable External editor (I'm using VSCode)
- Create a new script attached to a node in Godot 4
- In the _ready() function, add the lines
var x = 0
andx /= 0
- Run the scene that has the node with the script
- Godot 4 will break on the exception and if you switch to the
Script
tab to show the script in the editor, this script will be the old version without any external changes.
Bonus: If the error occurs on a line number that's further than the unmodified version, there will be an additional error in the console that says scene\gui\text_edit.cpp:4887 - Index p_line = 22 is out of bounds (text.size() = 12).
(In this case, the error occurred on line 23, and the original file loaded at project open was 12 lines long.) This shows that the parser is picking up the changes and throws the correct line number, but the editor just isn't reloading the file.
When saving externally via lsp, the source code of the internal script will be updated, but the editor is not notified. Can Resource.emit_changed
be used for this purpose, or still need to use a separate signal?
beta2 shows this message on pressing Reload
when this problem occurs:
core/object/object.cpp:1057 - Error calling from signal 'confirmed' to callable: 'ScriptEditor::ScriptEditor::reload_scripts': Method expected 1 arguments, but called with 0..