Skip to content

Commit bdedca2

Browse files
committed
Fix error when format on save is enabled and a tool script is actively running
Close #196
1 parent c48d445 commit bdedca2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

addons/GDQuest_GDScript_formatter/plugin.gd

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,12 @@ func _on_resource_saved(saved_resource: Resource) -> void:
234234

235235
script.source_code = formatted_code
236236
ResourceSaver.save(script)
237-
script.reload()
237+
# The argument (keep_state parameter) tells Godot to try to preserve the
238+
# state of the script instance, like static variables. Without this,
239+
# attempting to reload tool scripts will fail with an error because they
240+
# are already instantiated in the editor and instantiated scripts are
241+
# not allowed to force reload without unloading first.
242+
script.reload(true)
238243

239244
var script_editor := EditorInterface.get_script_editor()
240245
var open_script_editors := script_editor.get_open_script_editors()

0 commit comments

Comments
 (0)