Godot Version
4.2.2 Stable
Question
Full Error:
E 0:00:00:0305 deck_entry.gd:81 @ load_from_file(): Error constructing a GDScriptInstance.
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> modules/gdscript/gdscript.cpp:188 @ _create_instance()
deck_entry.gd:81 @ load_from_file()
deck_entry_display.gd:18 @ _ready()
Here is the additional context:
Saving and loading methods for this class:
func save_to_file(folder_path: String) -> Error:
# Construct the full file path
var file_path := folder_path + "/" + card.id_string + ".tres"
# Save the resource to a file
var error := ResourceSaver.save(self, file_path)
if error != OK:
print("Error saving DeckEntry: ", error)
return error
static func load_from_file(file_path: String) -> DeckEntry:
# Load the resource from the file
var resource : Resource = ResourceLoader.load(file_path)
print(file_path)
if resource is DeckEntry:
return resource as DeckEntry
else:
print("Error loading DeckEntry from file: ", file_path)
return null
Here is the code I ran to produce the error from another class:
var d := DeckEntry.new(preload("res://resources/cards/test_card.tres"))
d.save_to_file("res://resources/decks/bbb/deck_entries/main/")
deck_entry = DeckEntry.load_from_file("res://resources/decks/bbb/deck_entries/main/test_card.tres")
Notes:
- The resource does exist under the name at the file path
- I have deleted and created new resources but the same error occurs
- The resource does reference the correct script
- The resource is in fact of type DeckEntry in the inspector
- However when checking the type of the resource when loading it from code I can see that it is of type resource but not DeckEntry for some reason.
- Casting it to DeckEntry immediately also did not help
Any help is appreciated. I have sadly no clue what is going on and this is really blocking any progress.