An Array[Resource] has entries that aren't recognized as the Resource?

Godot Version

4.3

Question

I have the following code that has worked for months which suddenly broke for unknown reasons. So basically I have the following function:

func load_deck(deck_instance : C_UpgradeDeck, deck_res_path : String):
	var deck_resource : R_UpgradeDeck = load(deck_res_path)
	deck_instance.resource = deck_resource
	for upgrade : R_Upgrade in deck_resource.upgrades:
		if upgrade is R_Upgrade:
			deck_instance.upgrades.push_back(C_UpgradeEntry.create(deck_instance, upgrade))
		elif upgrade == null:
			printerr("R_Upgrade is null: ", upgrade.resource_path)
		else:
			printerr("R_Upgrade is not considered an R_Upgrade: ", upgrade.resource_path)

The “if upgrade is R_Upgrade” line is here to demonstrate how the code breaks- it should be impossible for upgrade to be anything other than an upgrade, yet that’s exactly what is happening here and prints this SOME OF THE TIME:

Check out my R_UpgradeDeck, which shows the type and example of the deck_resource.upgrades I’m looping through:


(Note that its an Array[R_Upgrade] so how could any not be an R_Upgrade?)

This function works with other decks/arrays (you can see in the errors above that the first two R_Upgrade don’t trip the error too.

No noticeable difference in the inspector between one that works and one that breaks:

The only difference I managed to find was that at runtime, the ones that work will populate the inspector for the upgrade:


But the ones that break only look like this:
image
The script is still recognized as an R_Upgrade though…

Is this corruption? If so, any ways to fix? My source control doesn’t register any differences between the broken R_Upgrades and I have lots of work I don’t want to revert :confused:

Any ideas is much appreciated. Thanks!

I’m not sure why the runtime inspector of a working R_Upgrade shows members but also an unfilled R_Upgrade section…

The error this causes if the function is called:
Invalid type in function ‘create’ in base ‘GDScript’. The Object-derived class of argument 2 (Resource) is not a subclass of the expected argument class.

Which leads me to think the R_Upgrade is only being seen as a Resource. But if that was the case, how would it be in an Array[R_Upgrade]?

The R_Upgrades that were broken were also being preloaded in a global file elsewhere. For some reason, changing it from preload to load fixed the issue.

Is there maybe some maximum on preload before it starts breaking shit? :thinking: