Godot Version
Latest master (v4.4.beta.custom_build [36d90c73a]
) but could reproduce on v4.3
as well
Question
Hi, I have this issue with saving resources that is driving me insane, but I can’t even tell whether it’s my misunderstanding, godot’s bug or addon’s bug, so any hints would be tremendously helpful!
tl;dr: subresource in a resource is “randomly” replaced with new resource with the same content (but different reference) after saving it using ResourceSaver.save
–
I have addon introducing a very simple custom resource script with exported property subresource
that holds a child Resource.
I have created instance of this custom resource, assigned new Resource as the subresource and saved as .tres
And then there is this trivial plugin which loads the saved resource linked above and 1. saves the resource on _save_external_data
. 2. observes when the reference in the subresource
property changes (which I’d expect shouldn’t happen by itself)
Now when I open the a scene containing Terrain3D node in editor, press Ctrl+S to save the scene, focus different window and then focus the godot editor again, the subresource reference suddenly changes!
Here’s video of the reproduction
Now, I’ve mentioned the Terrain3D node because I wasn’t able to reproduce it when saving scene without that node. And you can notice there’s also a MeshInstance3D in the scene. When I remove it, the issue is suddenly gone! Also it cannot be just any MeshInstance3D, when I create one with primitive mesh (such as sphere) the issue is still gone. It needs to be MeshInstance3D with ArrayMesh that is stored in the scene.
The set of conditions for this issue to appear seems kinda random, the fact it happens only after unfocusing and focusing the editor window is insane lol. My guess is that under some condition, the Terrain3D node calls some godot internal function which forces it to reload all resources and while resources with resource_path
are somehow cached so its reference doesn’t change, but all sub-resources are constructed again. But even that wouldn’t explain the required (un)focusing of the window lol.
This respository contains minimal reproduction example I’ve managed to create. Install the terrain3d plugin into addons/ before opening the project though.
I am afraid the simple answer is going to be: inline sub-resources may change at any time over the editor runtime so we shouldn’t store references to them and always access them through the saved resource… but still wanna hear someone’s opinion on this.
Sorry for the long post and thank you for any kind of explanation.