godotengine / godotengine/godot

Different behavior of @export custom Resources when reloading current scene and loading a new scene

Open
#112,581 1 comment 1 reaction 0 assignees View on GitHub
bug needs testing topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Version: 4.5.1.stable

In my personal project the issue was present in older 4.x stable versions as well, however I was certain it was me doing something wrong. Since the bug was pretty minor to me, I just avoided using "reload_current_scene" until I came back to it to understand where my code is messing up.

### System information

Godot v4.5.1.stable - Windows 11 (build 26200) - Multi-window, 1 monitor - OpenGL 3 (Compatibility) - NVIDIA GeForce RTX 3060 Ti (NVIDIA; 32.0.15.8108) - 11th Gen Intel(R) Core(TM) i5-11600K @ 3.90GHz (12 threads) - 15.87 GiB memory

### Issue description

When a custom resource type is created and saved as a file, you can load it in an exported field. The state of the resource on the disk isn't changed, but changes can be done in runtime (like in the project attached, a `count` field is incremented). Current scene is the only place where resource is used. When `get_tree().reload_current_scene()` is called, the state of the custom resources isn't reset to how it is on the disk. This is not the expected behavior (well, at least I expected). However, if you go to another scene and then reload the previous scene, the state of the resorce is reset - exactly like the expected behavior.
I believe that the final result of `reload_current_scene()` and loading current scene from a different one should be identical.

### Steps to reproduce

General steps:
1. Create a custom resource.
2. Save it to disk.
3. Load in an exported field in current_scene.
4. Change the resource fields.
5. Call `get_tree().reload_current_scene()`.
6. Resource isn't reset.

For attached project:
1. Open the project
2. Click any of the "Count +1" buttons for how many times you like
3. Press "reload_current_scene()" button
4. Press "Go to Scene 2"
5. Press "Go to Scene 1"
6. Compare results

### Minimal reproduction project (MRP)

[ResourceBug.zip](https://github.com/user-attachments/files/23438999/ResourceBug.zip)

Contributor guide

Open the contributing guide

Research direction

Open the attached ResourceBug.zip and reproduce the difference between get_tree().reload_current_scene() and leaving the current scene before returning to it. Trace how the custom resource loaded in the exported field is handled during both scene-loading paths. Done means reloading the current scene resets the resource state to its saved-on-disk values, matching the other path.

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
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.