Repository: godot
Issue: Incorrect value loaded from .tres file for instances of custom classes.
Labels: bug,topic:core

### Tested versions

v4.3.stable.arch_linux

### System information

Godot v4.3.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 01 Nov 2024 03:30:41 +0000 - Wayland - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3090 (nvidia; 565.57.01) - AMD Ryzen 7 5800X 8-Core Processor (16 Threads)

### Issue description

I initially raised this issue here: https://github.com/derkork/godot-resource-groups/issues/13 as I thought it must have been something caused by the plugin when I failed to reproduce it directly using `ResourceLoader`. I since tried recreating the problem in a clean project using the plugin and failed to reproduce and upon further troubleshooting I believe again that it is an engine issue.

I won't include as much context here as some of it isn't relevant, but you can view the initial issue for more detailed context.

Essentially I have the following custom resource types, formatted as `Class -> ParentClass`
`Item -> Resource` This class is also fairly lightweight. It is used to wrap different data types representing things that are stored in an inventory. The two main types are `Spell` and `SpellMod`.
`SpellItem -> Item` This is an item with a `spell: PackedScene` property that holds the code / data relevant to actually creating an instance of a spell.
`SpellModItem -> Item` This is an item with a `spell_mod: SpellMod` property.
`SpellMod -> Resource` This is a pretty lightweight abstract class that describes some data with a `mod(spell: Spell)` method.
`FlightPathMod -> SpellMod` An example of a SpellMod subtype that actually has an implementation and some additional data. In this case it will change the flight path of a projectile (eg a fireball). All `FlightPathMod` instances will share the same script, and different mods are created by changing the other data stored in this resource.

I have two different FlightPathMod resources: `wave_flight_mod.tres` and `zig_zag_flight_mod.tres` with different data for calculating the new flight path saved as external resources (using built in resource types, also saved in their own `.tres` files and loaded through the editor when creating these resource files)

I then also have a SpellModItem resource for each of these mods that keeps a reference to them (set up through the inspector by loading into @export vars as above) as well as some item specific metadata.

The issue is that once I save these SpellModItem resources and reload the project, the editor seems to load them incorrectly. If I open `wave_flight_mod.tres` by double clicking it in the editor's File System window, it will display the data in the inspector, but with the `spell_mod` property incorrectly being the resource at `res://.../zig_zag_flight_mod.tres`. When I view `wave_flight_mod.tres` in a text editor, the path appears to be `res.../wave_flight_mod.tres` as expected. You can see in the screenshot below how the same file is being viewed in the inspector and vscode yet the values are different.

![image](https://github.com/user-attachments/assets/ba5c7aff-4f7b-466d-9e37-8c0b5ae4b76c)


I can try resetting the values and saving again, but the problem reappears when I reload the editor. If I don't reload the project and attempt to run the game, the data looks correct in memory (viewed in the debugger) when first loaded from disk, but once the data is copied into another var the reference breaks. I am not sure if this is happening when the second mod gets loaded. Stepping through the debugger line-by-line makes it seem like that is not the case but they are loaded asynchronously so I suspect the tools are being a bit misleading here.



### Steps to reproduce

I outlined the steps I take to reproduce the issue within my project above, but I have not been able to successfully reproduce it in a fresh project, even after a few hours of trying. If anyone has suggestions on what might be causing issues I am happy to try updating my attempt at reproducing the issue to help create an example.

I understand this makes it difficult to action this bug. I am mostly hoping that someone can at least give me some advice on what to try to help discover the root cause.

### Minimal reproduction project (MRP)

See above.