Inspector data present but absent when querying at runtime, ResourceLoader issue

Godot Version



Debugging the inspector shows me that data is present, but when trying to access it in debug mode I get an empty array (egr at the bottom). This is what I get after loading the data

I’m using ResourceSaver and ResourceLoader as such:

static func createSave():
	var instance: PlayerData = PlayerData.getInstance()
	var rVal =, PATH+pathPlayerData)
static func loadGame():
	var playerDataLoaded: PlayerData = ResourceLoader.load(PATH+pathPlayerData)
	if playerDataLoaded:
		PlayerData.instance = playerDataLoaded
		print("Player data not found")

with a single data class to save:

extends Resource
class_name PlayerData

static var instance: PlayerData = null
@export var gold: int = 50
@export var maxCombatantLevel: int

@export var combatants: Array[Combatant] = []
@export var equipments: Array[Equipable]  = []
@export var unlockedLocation: Array[FightingLocation]  = []
@export var combats: Array[Combat] = []

func _init(): ...

I don’t know how much of the code I can put here, but the whole project on this branch is available and I constated the issue when stopping there: github com/pyrovoice/GuildManagerGodot/blob/resourceandsaves2/Combat/ (add a dot, sorry I’m locked at two links) . At this point I try to access an array that’s shown to contain the loaded data but gives me something empty when actually accessing it.

I’m at my wit’s end as to what could be going on here, if you have any clue or stuff to try please let me know :slight_smile:

I’m not sure I understand your question (your links do not work for me), but it looks like you are mixing up the resource’s custom class type with globally accessible variables.

A resource is a serializable object that can be saved to disk, you can think of it like a variable type but it is not a global variable. It looks like what you want to do is use a single instance of your custom resource for player data that is globally accessable at runtime.

To achieve this you could create an autoload and in the autoload script have a variable of type PlayerData. When you update the data, access that variable, and when you call access that specific variable as well (not the PlayerData class type).

If you want to set the values in the inspector and use those during runtime, you can save an instance of your resource and then assign that specific instance to the variable in your autoload.

tl;dr Make sure you are saving the instance of the resource that actually has data in it.