I've encountered a problem with loading and saving custom objects in Godot 3.3.2 using the store_var
and get_var
functions of the File
object with the allow_objects
/ full_objects
bools set to true
.
I've made a minimal example project to illustrate the problem: https://github.com/marc-jones/godot-save-load
This project creates a save file the first time it is run, then reads from that save file each subsequent time it is run. When running the project in the editor the correct behaviour occurs. The first time you run the project, "null" is displayed on the screen because the save file doesn't exist. All subsequent times the project is run, "foobar" is read from the save file created the first time the project was run and displayed on screen.
I then delete the save file with the bash command:
rm ~/.local/share/godot/app_userdata/godot-save-load/test.save
When running the build of the project (which has debug), the first time it's run "null" is also displayed. Subsequent times, however, no text is displayed (because the save
object is null and therefore doesn't have the property text
) and the following message is displayed in the terminal:
ERROR: instance_create: Script inherits from native type 'Reference', so it can't be instanced in object of type 'Node'.
Interestingly, I can induce the error in the editor. If I delete the save file and run the build to create the save, then run the project in the editor, the same error as above is displayed. Equally, if I delete the save file and run the project in the editor to create the save file, then run the build, "foobar" is displayed. This makes me think something is going wrong with saving the file, although diff
shows that the two save files created by the editor and the build are identical.
The same error also occurs with HTML5 and Android builds.
I was going to create an Issue on the Godot GitHub, but I'm not sure whether this is a coding problem I've created or an actual bug! I guess either way, different behaviour between the editor and builds should be minimised. Any help on this would be greatly appreciated!