godotengine / godotengine/godot
Resource Saver/Loader not saving exported resource values
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
My version: 4.6 Stable (Windows)
### System information
Godot v4.6.stable - Windows 11 (build 22631) - Multi-window, 1 monitor - OpenGL 3 (Compatibility) - NVIDIA GeForce GTX 1650 (NVIDIA; 32.0.15.5612) - 11th Gen Intel(R) Core(TM) i5-11400H @ 2.70GHz (12 threads) - 31.76 GiB memory
### Issue description
You'll notice in the example project that I have exported every variable. I know that's important.
I have a class, SaveResource, that holds a resource that stores character stats:
When I save, no matter what I've tried, Godot only writes the default values to the save file:
Look at line 7. I am writing the stats from the saved file to the Global object that keeps them (the inspector shows the default stats no matter what, I have no idea if this is default behavior or not):
Even though Godot is able to successfully write the stats on the screen when the character levels up, and it *does* run the code to update the stats, it seems to totally ignore line 7 in the previous screenshot and writes whatever the current values are.
I would expect the save button to save the values in memory for the TRES file and reproduce them when loaded. This code is almost entirely copied from GDQuest, and I've tried to reproduce it as faithfully as I can. If I've misunderstood something, it may be the documentation that needs updating, and I'm happy to make an issue for that instead. The GDQuest article that this code came from is here: [https://www.gdquest.com/library/save_game_godot4/](url)
I know Godot can't save _nested_ resources, but to the best of my understanding this isn't a nested resource. The last code example in the GDQuest article makes me think what I'm doing here should work.
### Steps to reproduce
1. The minimum reproducible project stores character stats as a resource file.
2. This file is accessed throughout the project as a global node.
3. The UI system is able to accurately show the character stat values.
4. When the user "levels up" (when you click the button to change the stat values), the UI will update the stats accordingly.
5. Should the user need, the reset button will reset the stats to base.
6. The save button should save the stats, and the print statement included in the save button code would leave you to believe that it is saving the correct values. (If you use a break point, you can see that it only saves default values. The print statement is misleading.)
7. The load button should bring up the saved values, instead, it only loads the current values in memory. There is a print statement that proves that it is clickable.
### Minimal reproduction project (MRP)
https://github.com/beanjbunny/save-demonstration or,
[save-demonstration.zip](https://github.com/user-attachments/files/27779229/save-demonstration.zip)
Contributor guide
Research direction
Start with the linked save-demonstration minimal reproduction project and trace its SaveResource flow through ResourceSaver and ResourceLoader. Compare the exported resource values in memory with the values written to and read from the TRES save file, including the save and load button paths. Done means determining whether the behavior is an engine bug or a documentation issue and documenting the result with a reproducible test case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- godot
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100