Lets assume I have a resource:
@tool
class_name SomeRes
extends Resource
@export version := 1
@export var foo: bool
Now at some point during development, I rename the field foo into bar and update the version to 2. I create a static class to manage this
@tool
class_name SomeResMigrator
static func migrate_v1_v2(old_res: SomeRes) -> SomeRes:
var new_res := SomeRes.new()
new_res.bar = old_res.foo
return new_res
Now in theory what this means is that when my plugin notices that the resource being loaded is out of date, it would create a copy of the resource that is up to date with the current SomeRes class, and strip the data from the old one.
The issue is that upon loading the .tres, Godot completely discards any fields that don't match up with the current definition. The result is that when I pass a version 1 SomeRes into the migration function, it doesn't even have anything in the foo field, resulting in an error for trying to access a Nil property
How do I be sure that Godot loads the resource .tres as-is including fields that don't exist in the current SomeRes definition so that I may copy the data from such fields into a new object?