Wrong type when loading subresources

Godot Version



For the purpose of a cache, I am saving and loading a resource (.tres) file from the user:// folder. The saving works alright, but I am having an issue with the loading part: the type of some subresources is not right. Mainly a class I have called “NonNetDocument” (as I am using some networking documents between the client and Firestore Firebase). They are saved in the correct way:
(points to)

→ They are saved pointing toward the right script (and thus class?)

But are then loaded as Resource instead, which disables me from accessing properties such as the doc_name in the image above.

So, my question is: how can I load a resource so that it’s subresources become the right type, instead of always the type Resource.


It shouldn’t matter if it’s cast down to a resource, it will still be the same class.

As you can see it inherits from Resource class.

If you want to make sure NonNetDocument is seen for what it is. You can declare a static type like so.

var NonNetDocument : GDScript

You can also cast it if you load with code.

var s = load(res) as GDScript

Hey, I should’ve specified the issue better. Let me give you some more info:
results in printing
and an error: “Invalid get index ‘doc_name’ (on base: ‘Resource’)”
As you can see from my save file, there is definitely a property by the name “doc_name”, but it cannot be accessed like this.

Also casting it to GDScript results in as well.

So, what I’m saying is, that the NonNetObject for whatever reason is loaded as a Resource, which probably clears its fields specific to the NonNetObject class, thus not allowing me to use them.

Another thing that may be causing the issue: I am loading the cache as a dictionary. So there can’t really be specific types that I cast to anywhere.

Can you show me what the declaration of NonNetDocument.

As well as the base type of the non_net_doc.gd?

And code on how the resource is saved?

Hey, apologies for the very late response. I ended up fixing the issue by saving the resources as dictionaries instead of Resources.

There’s always a workaround :smiley: