Using ResourceLoader to load a class that extends Resource produces an incomplete error

Godot Version

4.3

Question

Can I save/load an object via ResourceSaver/Loader if the resource being saved is a child of a singleton class?
I’m saving my object with ResourceSaver, and i can see that it saves properly, but when i load it i get this error message.


Trying to assign value of type Resource to a variable of type ".
It seems like the error is being cut off, and this method of loading a saved resource works in another project. Am i trying to do something i shouldn’t be? What’s going on here?

Moving the load function outside of the State singleton produces a different error


Invalid assignment of property or key 'state' with value of type 'Resource' on a base object of type 'Node (state.gd)'.

Can you show the contents of the resource that gives the error?

Yup, here’s the contents of the asdf.tres file:

[gd_resource type=“Resource” load_steps=2 format=3]

[sub_resource type=“GDScript” id=“GDScript_v3dew”]

[resource]
script = SubResource(“GDScript_v3dew”)
Prestige = 2
PrestigeTokens = 2
Score = 13.3856

Got it figured out. The StateObject class cannot be a subclass, otherwise ResourceLoader won’t recognize it, and save it instead as a normal resource. I created a minimal working example project for anyone that runs into this problem with a singleton state manager setup, it’s on my github GitHub - snapish/MinimalStateManagerSingleton: Example project for using a global class in gdscript to save/load custom resource files to file

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.