Reference to subresource inside saved resource keeps changing during editor runtime

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.

Tested on:
Windows 11 24H2
Godot v4.3.stable.official [77dcf97d8]

and was unable to reproduce. Am I correct in the assumption that you are using Linux? Are you able to test with a similar configuration that I have?

Interesting, didn’t think this might be OS specific. Going to try to reproduce on windows.

Managed to reproduce on Windows 11 as well. Godot 4.3 stable, fresh clone of the repository, latest Terrain 3D
Animation

So it behaves differently on different setups, but it’s not related to OS or godot version… even more mind-boggling.

EDIT: funfact: the issue is not present when I switch to compatibility renderer…

I tried to reload the project again, assign different resources, change windows in multiple ways while saving, while not saving, … I am still unable to reproduce.

The line only gets printed when I manually change the resource (as is expected). If I were you I would try reporting an issue on GitHub (GitHub · Where software is built). This may be an issue or is an expected behavior I am not familiar with.

Sadly with me not being able to reproduce I can’t help you a lot more.

Good Luck

You can maybe try to rollback your NVIDIA drivers. I am on an old version myself right now since the latest one has known issues with the Vulkan renderer and I was getting visual artifacts. While I doubt this is the actual issue it is a disparity in our configurations.

To make sure it’s not hardware specific I’ve tried reproducing it on my laptop with integrated intel GPU and the issue persists. I’ll probably create an issue then. Thank you very much for trying to reproduce it like this.