godot icon indicating copy to clipboard operation
godot copied to clipboard

Don't save unnecessarily with `save_before_running`

Open KoBeWi opened this issue 1 year ago • 6 comments

When save_before_running is enabled, it will save all scenes, which can lead to longer running times if you have many opened scenes. That's rather absurd.

This PR changes that mechanism to only save when there are unsaved changes in the scene (which we can detect pretty reliably).

KoBeWi avatar Mar 30 '24 07:03 KoBeWi

This PR changes that mechanism to only save when there are unsaved changes in the scene (which we can detect pretty reliably).

With editor plugins, this may not be the case: https://github.com/godotengine/godot-proposals/issues/2153

I fully support this PR, but we need to have zero false negatives before it can be merged without risk. People are used to the current behavior, so not saving some scenes that should be saved due to a bug could end up wasting hours of people's time.

Calinou avatar Apr 01 '24 23:04 Calinou

Excited to see this change come in! The current behavior is triggering a lot of unnecessary file watch behavior since unchanged scenes get new modify times.

I am wondering if rather than changing the behavior only for save_before_running it might make more sense to change the implementation of "Save All Scenes" instead (with the same caveats @Calinou pointed out)?

The current behavior of "Save All Scenes" is really "Re-Save All Open Scenes" and that's not super useful. I'd expect it to either 1) save all dirty scenes (strict subset of open ones so I think that's why the current implementation is what it is) or 2) Re-Save All Scenes regardless of open status. Doing a full re-save but only of open scenes feels like a weird in-between that isn't correct for either reasonable interpretation.

Personally I'd prefer to have it just do option #1 (hence this suggestion) but I could see a use case for full re-save too. Most applications that support multiple documents simply have a "Save All" option (commonly bound to Ctrl-Shift-S) which essentially just takes care of dirty docs so I think it's reasonable to expect users would interpret it as this.

Also I noticed it technically resaves everything that's open (including shaders and scripts) so "Save All" might be a more correct name as well.

ogapo avatar Apr 23 '24 22:04 ogapo

Ok I reworked Save all Scenes. It can be used only if any scene is unsaved.

https://github.com/godotengine/godot/assets/2223172/f544c7d1-e853-4d20-9ac2-9fcbf66ccf3c

KoBeWi avatar Apr 24 '24 14:04 KoBeWi

This change works like a charm for scenes and scripts. In testing, however, I noticed that any open shaders always re-save any time any scene is saved (whether or not they are modified). I tracked it down to needing an is_unsaved check in ShaderEditorPlugin::save_external_data() i.e.

void ShaderEditorPlugin::save_external_data() {
	for (EditedShader &edited_shader : edited_shaders) {
		if (edited_shader.shader_editor) {
			if (edited_shader.shader_editor->is_unsaved()) {
				edited_shader.shader_editor->save_external_data();
			}
		}
	}
	_update_shader_list();
}

It might be worth including that in this PR also for completeness sake.

ogapo avatar Apr 24 '24 16:04 ogapo

How does this work with changes to resources, instead of scenes? Currently I think a lot of the Godot workflow hinges on scene saving actually saving all dependent resources, even if there's no change to the scene itself. Saving changes to resources specifically is pretty cumbersome currently with just the save button in the inspector IIRC.

akien-mga avatar Apr 25 '24 11:04 akien-mga

Apparently if you make a change in external resource, the editor will save the current scene which will also save that resource 🤔 And if you have no open scenes, the external changes are not saved when running. But this is the same behavior as before this PR, so it can be fixed separately.

EDIT: Guess what, a fix already exists and waits: #85513

KoBeWi avatar Apr 25 '24 12:04 KoBeWi