Subresources saving without NOTIFICATION_EDITOR_PRE_SAVE firing
Tested versions
v4.3.stable.official [77dcf97d8] (also was occurring on 4.2 stable)
System information
Godot v4.3.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated AMD Radeon RX 6600 (Advanced Micro Devices, Inc.; 31.0.12027.9001) - AMD Ryzen 5 3600 6-Core Processor (12 Threads)
Issue description
A node which modifies a sub-resource of a resource, for purposes of a tool script, fails to run NOTIFICATION_PRE_SAVE on the node before saving changes to the subresource, when saving a DIFFERENT scene in the editor.
Either the NOTIFICATION_PRE_SAVE/NOTIFICATION_POST_SAVE should fire for the node, or the changes to the subresource should not be saved (since no node using that resource or subresource is being saved?)
The actual issue here is that I have a shader which adjusts a texture size based on a tilemap; the size differs from scene to scene, but saving any of the scenes that uses this, appropriately resizes the texture to 1024x1024 in the PRE_SAVE notification - but when saving literally any other scene, I end up with some random other values in my git changes that I need to avoid accidentally committing. (The entire point of the PRE_SAVE here was to prevent any git changes to that...)
Steps to reproduce
Have a tool script node that uses NOTIFICATION_EDITOR_PRE_SAVE, making a modification to a sub-resource of a resource of the node; and then modifies it again in NOTIFICATION_EDITOR_POST_SAVE or somewhere else (point being, the value while the editor is open, is different from the value on disk, as the value is always changed immediately before saving to disk).
With that scene open, save a different scene. NOTIFICATION_EDITOR_PRE_SAVE does not fire, but any changes to the sub-resource ARE saved, thus saving the value that is intended to never be saved.
Minimal reproduction project (MRP)
mrp_presave.zip
With both presave_example.tscn and random_other_scene.tscn open in the editor, note the behavior when saving.
- With
presave_example.tscnas the active scene, saving does as expected; the PRE_ and POST_ save events fire, anddummy.tresreadswidth = 50on theNoiseTexture2Das intended. - With
random_other_scene.tscnas the active scene, saving does NOT fire the PRE_ and POST_ save events forpresave_example.tscn, but the changes todummy.tres(which is only used bypresave_example.tscn, and is not at all used byrandom_other_scene.tscn, are saved anyway, thus savingwidth = 200to theNoiseTexture2Dindummy.tres. - Additionally, note that if
presave_example.tscnis not open at all, savingrandom_other_scene.tscndoes NOT cause this behavior. It appears to me as though it is saving the resources used by all open scenes, instead of only the scene(s) being saved.
I am having trouble even getting the editor to send the notifications at all. I copied the code, created a fresh scene in my project, and pasted it into a script, removing the functions. The notification never hits the node on save, whether I am focused on the scene or not.
- This is irritating, as I have sprites randomly jiggling, and I want them to always save with rotation 0.0 to not mess with git
- The editor also crashes when I turn on "Save on Focus Lost" and change focus, not sure if it's related.
I downloaded the save, and somehow the notifications worked: although, with the issues described by OP.
I am using Godot 4.2.2 nix package with x86_64 Linux 6.6.52 NixOS, 24.05 (Uakari), 24.05.5366.fbca5e745367, 11th Gen Intel® Core™ i3-1115G4 @ 3.00GHz and integrated graphics :cry:
I am also using rust gdext
This is my project: https://github.com/donottellmetonottellyou/Kindergarten-Word-Finder
I think I may have run into the same issue. In my case, I'm resetting some values in a custom node before the scene is saved. In the scene that is selected in the editor the notifications work correctly, but the editor also saves other open scenes even when pressing Ctrl-S (Save Scene), and the save notifications don't trigger on those other open scenes.
This might be actually two issues:
- Action "Save Scene" saves all scenes, making "Save All Scenes" redundant. Or am I missing something?
- Pre/post save notifications aren't sent to nodes in scenes other than the current selected scene in the editor.