Saving and loading a resource resets some export variables

Godot Version

v4.2.1.stable.official [b09f793f5]


I am using resources to save player data in my game, and saving and loading the resource resets some export variables to their default values, and they are supposed to retain their values that were changed during gameplay.

My save game resource code

@export var random_seed: int
@export var player_stats: PlayerStats
@export var round_stats: RoundStats
@export var shop_inventory: ShopInventory
@export var books: Array[Book]
@export var phase: Phase

func save_game() -> void:, PATH)

static func save_exists() -> bool:
	return ResourceLoader.exists(PATH)

static func load_game() -> Resource:
	return SafeResourceLoader.load(PATH)

The specific thing not saving is a member var of the book class/resource, whose member vars are shown below. Some book items scale over time, and there is a function that adds to the letter score or word mult of those books, and these values are being reset to 0 when loading a saved game.

@export_multiline var book_title: String
@export var id: String
@export var type: Type
@export var book_texture: Texture
@export_multiline var tooltip: String
@export var cost: int

@export var has_letter_score: bool
@export var letter_score: float
@export var has_word_mult: bool
@export var word_mult: float
@export var rarity: Rarity

Interestingly, this only happens when closing the game window and reopening it. If I quit to the main menu then continue the game these values are retained. Any assistance would be appreciated.

I found a solution, making a copy of the book resource when adding it to the player’s inventory instead of using the base resource makes it retain the value when saving. Seems like in order for a resource to be properly saved it must be a unique copy of that resource.