Context
I’m currently developing an in-house software to manage a database of hardware. The database is a class, that is saved as a resource with
ResourceSaver.save(my_database, database_path)
This database is loaded with
load(database_path)
From within the database class. This class has only one variable, an array of “Gear” (hardware element if you prefer). The gear class contains multiple variable, with the export keyword so that it is saved.
Everything works like a charm, but I’m trying to build a software which handle any change in the structure (I mean changes in the number of variables in the Gear class, or their name, or type of variable).
What I want to achieve
I’m simplifying a bit. Let’s say my Gear class has only one variable :
@export var id: int
So my database contains an array of this single-variable Gear instance.
What happens if :
- I save the current database (single variable in Gear instances).
- I modify the software by adding another variable to the Gear class such as below
- I launch the software again, and load the resource database.
@export var id: int
@export var name: String
My question
Godot would expect the resource to contain 2 variables by Gear, but the saved resource only contains 1. What would happen ? Will Godot add a default value to this new variable, or throw an error, or something else ?
More generally, how should I handle a saved resource, if in the future I want to add more variables, or delete some, or rename ?
I would like the user experience to be hasslefree, any changes to the software should be able to still load a previous version of the database.